diff options
author | Jouni Malinen <j@w1.fi> | 2012-06-28 13:25:48 +0300 |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2012-06-28 13:25:48 +0300 |
commit | 3cf7a59d4f4345c24f99e5422a680cec6b9356d0 (patch) | |
tree | cf6f42aa1653b9591a525f9cff7b5cfd4a5ef93c /hostapd | |
parent | 5bb7ae1f0ccca1474d8972dab582d136fef8d65b (diff) | |
download | external_wpa_supplicant_8_ti-3cf7a59d4f4345c24f99e5422a680cec6b9356d0.zip external_wpa_supplicant_8_ti-3cf7a59d4f4345c24f99e5422a680cec6b9356d0.tar.gz external_wpa_supplicant_8_ti-3cf7a59d4f4345c24f99e5422a680cec6b9356d0.tar.bz2 |
WPS: Add new mechanism for generation NFC configuration token
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>
Diffstat (limited to 'hostapd')
-rw-r--r-- | hostapd/ctrl_iface.c | 33 | ||||
-rw-r--r-- | hostapd/hostapd_cli.c | 24 |
2 files changed, 57 insertions, 0 deletions
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index ec5529e..0fa1764 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -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) { diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 2d0445e..ed52187 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -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 }, |