wds: add a separate --set-ip-family option
[project/uqmi.git] / commands-wds.c
index fabb5f4..7bb75da 100644 (file)
@@ -82,6 +82,32 @@ cmd_wds_set_autoconnect_prepare(struct qmi_dev *qmi, struct qmi_request *req, st
        return QMI_CMD_DONE;
 }
 
+#define cmd_wds_set_ip_family_pref_cb no_cb
+static enum qmi_cmd_result
+cmd_wds_set_ip_family_pref_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
+{
+       static const struct {
+               const char *name;
+               const QmiWdsIpFamily mode;
+       } modes[] = {
+               { "ipv4", QMI_WDS_IP_FAMILY_IPV4 },
+               { "ipv6", QMI_WDS_IP_FAMILY_IPV6 },
+               { "unspecified", QMI_WDS_IP_FAMILY_UNSPECIFIED },
+       };
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(modes); i++) {
+               if (strcasecmp(modes[i].name, arg) != 0)
+                       continue;
+
+               qmi_set(&wds_sn_req, ip_family_preference, modes[i].mode);
+               return QMI_CMD_DONE;
+       }
+
+       uqmi_add_error("Invalid value (valid: ipv4, ipv6, unspecified)");
+       return QMI_CMD_EXIT;
+}
+
 static void
 cmd_wds_start_network_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
 {
@@ -211,13 +237,12 @@ static void wds_to_ipv4(const char *name, const uint32_t addr)
 
 static void wds_to_ipv6(const char *name, const uint16_t *addr)
 {
-       int i;
-       struct in6_addr ip_addr;
        char buf[INET6_ADDRSTRLEN];
+       uint16_t ip_addr[8];
+       int i;
 
-       for (i = 0; i < ARRAY_SIZE(ip_addr.s6_addr16); i++) {
-               ip_addr.s6_addr16[i] = htons(addr[i]);
-       }
+       for (i = 0; i < ARRAY_SIZE(ip_addr); i++)
+               ip_addr[i] = htons(addr[i]);
 
        blobmsg_add_string(&status, name, inet_ntop(AF_INET6, &ip_addr, buf, sizeof(buf)));
 }
@@ -247,7 +272,7 @@ cmd_wds_get_current_settings_cb(struct qmi_dev *qmi, struct qmi_request *req, st
 
        t = blobmsg_open_table(&status, NULL);
 
-       if (res.set.pdp_type && res.data.pdp_type < ARRAY_SIZE(pdptypes))
+       if (res.set.pdp_type && (int) res.data.pdp_type < ARRAY_SIZE(pdptypes))
                blobmsg_add_string(&status, "pdp-type", pdptypes[res.data.pdp_type]);
 
        if (res.set.ip_family) {