]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Add new mechanism for generation NFC configuration token
authorJouni Malinen <j@w1.fi>
Thu, 28 Jun 2012 10:25:48 +0000 (13:25 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 28 Jun 2012 10:25:48 +0000 (13:25 +0300)
The new hostapd ctrl_iface command WPS_NFC_CONFIG_TOKEN can now be used
to fetch payload for an NFC configuration token so that an external
program can be used to write this on an NFC tag.

Signed-hostap: Jouni Malinen <j@w1.fi>

hostapd/ctrl_iface.c
hostapd/hostapd_cli.c
src/ap/wps_hostapd.c
src/ap/wps_hostapd.h
src/wps/wps.h
src/wps/wps_common.c

index ec5529e2e1e0c1751c04d451c3df1152036b0b74..0fa176411118b5acced4cd3d326ed9e324a6b6ad 100644 (file)
@@ -300,6 +300,36 @@ static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
 
        return ret;
 }
+
+
+static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
+                                                  char *cmd, char *reply,
+                                                  size_t max_len)
+{
+       int ndef;
+       struct wpabuf *buf;
+       int res;
+
+       if (os_strcmp(cmd, "WPS") == 0)
+               ndef = 0;
+       else if (os_strcmp(cmd, "NDEF") == 0)
+               ndef = 1;
+       else
+               return -1;
+
+       buf = hostapd_wps_nfc_config_token(hapd, ndef);
+       if (buf == NULL)
+               return -1;
+
+       res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
+                                        wpabuf_len(buf));
+       reply[res++] = '\n';
+       reply[res] = '\0';
+
+       wpabuf_free(buf);
+
+       return res;
+}
 #endif /* CONFIG_WPS_NFC */
 
 
@@ -802,6 +832,9 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
        } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
                if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
                        reply_len = -1;
+       } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
+               reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
+                       hapd, buf + 21, reply, reply_size);
 #endif /* CONFIG_WPS_NFC */
 #endif /* CONFIG_WPS */
        } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
index 2d0445ed4aac0bbb2abe3804d39fef70f9c2c067..ed52187fabf311a44fe98d7a37ec880f1d45c28c 100644 (file)
@@ -76,6 +76,7 @@ static const char *commands_help =
 #endif /* CONFIG_WPS_OOB */
 #ifdef CONFIG_WPS_NFC
 "   wps_nfc_tag_read <hexdump>  report read NFC tag with WPS data\n"
+"   wps_nfc_config_token <WPS/NDEF>  build NFC configuration token\n"
 #endif /* CONFIG_WPS_NFC */
 "   wps_ap_pin <cmd> [params..]  enable/disable AP PIN\n"
 "   wps_config <SSID> <auth> <encr> <key>  configure AP\n"
@@ -461,6 +462,28 @@ static int hostapd_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl *ctrl, int argc,
 
        return ret;
 }
+
+
+static int hostapd_cli_cmd_wps_nfc_config_token(struct wpa_ctrl *ctrl,
+                                               int argc, char *argv[])
+{
+       char cmd[64];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid 'wps_nfc_config_token' command - one argument "
+                      "is required.\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "WPS_NFC_CONFIG_TOKEN %s",
+                         argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long WPS_NFC_CONFIG_TOKEN command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
 #endif /* CONFIG_WPS_NFC */
 
 
@@ -763,6 +786,7 @@ static struct hostapd_cli_cmd hostapd_cli_commands[] = {
 #endif /* CONFIG_WPS_OOB */
 #ifdef CONFIG_WPS_NFC
        { "wps_nfc_tag_read", hostapd_cli_cmd_wps_nfc_tag_read },
+       { "wps_nfc_config_token", hostapd_cli_cmd_wps_nfc_config_token },
 #endif /* CONFIG_WPS_NFC */
        { "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin },
        { "wps_config", hostapd_cli_cmd_wps_config },
index e6c158aba9af920fe1b652be5d1261b7ea190091..b95b6170dbe05346a5925a19fe3755b2f388e441 100644 (file)
@@ -1584,4 +1584,26 @@ int hostapd_wps_nfc_tag_read(struct hostapd_data *hapd,
        return ret;
 }
 
+
+struct wpabuf * hostapd_wps_nfc_config_token(struct hostapd_data *hapd,
+                                            int ndef)
+{
+       struct wpabuf *ret;
+
+       if (hapd->wps == NULL)
+               return NULL;
+
+       ret = wps_get_oob_cred(hapd->wps);
+       if (ndef && ret) {
+               struct wpabuf *tmp;
+               tmp = ndef_build_wifi(ret);
+               wpabuf_free(ret);
+               if (tmp == NULL)
+                       return NULL;
+               ret = tmp;
+       }
+
+       return ret;
+}
+
 #endif /* CONFIG_WPS_NFC */
index 75a3bcb09fcdf6176ab79defa7740ab6ca298812..8256c0651e0bf4345dd255e12b87f2c7acf69225 100644 (file)
@@ -35,6 +35,8 @@ int hostapd_wps_config_ap(struct hostapd_data *hapd, const char *ssid,
                          const char *auth, const char *encr, const char *key);
 int hostapd_wps_nfc_tag_read(struct hostapd_data *hapd,
                             const struct wpabuf *data);
+struct wpabuf * hostapd_wps_nfc_config_token(struct hostapd_data *hapd,
+                                            int ndef);
 
 #else /* CONFIG_WPS */
 
index 927102f8ca13cfec39018e26a4a450966277b6d5..ca2f55c9628308573644f650ff08115b7457dd8c 100644 (file)
@@ -817,6 +817,7 @@ struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
 int wps_get_oob_method(char *method);
 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
                    int registrar);
+struct wpabuf * wps_get_oob_cred(struct wps_context *wps);
 int wps_attr_text(struct wpabuf *data, char *buf, char *end);
 
 struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname,
index 63857e0afce8c4d03768cf2514a91008aa4f6ef7..35ebec00a547f91bc08bf33cdb172740240a1bbe 100644 (file)
@@ -308,7 +308,7 @@ void wps_pbc_timeout_event(struct wps_context *wps)
 
 #ifdef CONFIG_WPS_OOB
 
-static struct wpabuf * wps_get_oob_cred(struct wps_context *wps)
+struct wpabuf * wps_get_oob_cred(struct wps_context *wps)
 {
        struct wps_data data;
        struct wpabuf *plain;