Skip to content

Commit

Permalink
sta_wps_read_pin: Calculate a unique PIN for each station
Browse files Browse the repository at this point in the history
One of the WPS tests requires each STA to have its own PIN. Calculate a
unique PIN for each station based on local MAC address instead of using
the same hardcoded PIN to meet this requirement.

Signed-off-by: Alexei Avshalom Lazar <ailizaro@codeaurora.org>
  • Loading branch information
Alexei Avshalom Lazar authored and Jouni Malinen committed Jan 29, 2019
1 parent 0c1d82d commit 0dae51c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
11 changes: 9 additions & 2 deletions p2p.c
Original file line number Diff line number Diff line change
Expand Up @@ -1624,11 +1624,18 @@ static int cmd_sta_set_wps_pbc(struct sigma_dut *dut, struct sigma_conn *conn,
static int cmd_sta_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
/* const char *intf = get_param(cmd, "Interface"); */
const char *intf = get_param(cmd, "Interface");
const char *grpid = get_param(cmd, "GroupID");
char *pin = "12345670"; /* TODO: use random PIN */
char pin[9], addr[20];
char resp[100];

if (get_wpa_status(intf, "address", addr, sizeof(addr)) < 0 ||
get_wps_pin_from_mac(dut, addr, pin, sizeof(pin)) < 0) {
sigma_dut_print(dut, DUT_MSG_DEBUG,
"Failed to calculate PIN from MAC, use default");
strlcpy(pin, "12345670", sizeof(pin));
}

if (grpid) {
char buf[100];
struct wfa_cs_p2p_group *grp;
Expand Down
2 changes: 2 additions & 0 deletions sigma_dut.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ size_t strlcpy(char *dest, const char *src, size_t siz);
size_t strlcat(char *dst, const char *str, size_t size);
#endif /* ANDROID */
void hex_dump(struct sigma_dut *dut, u8 *data, size_t len);
int get_wps_pin_from_mac(struct sigma_dut *dut, const char *macaddr,
char *pin, size_t len);
void str_remove_chars(char *str, char ch);


Expand Down
39 changes: 39 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,45 @@ void nl80211_deinit(struct sigma_dut *dut, struct nl80211_ctx *ctx)
#endif /* NL80211_SUPPORT */


static int get_wps_pin_checksum(int pin)
{
int a = 0;

while (pin > 0) {
a += 3 * (pin % 10);
pin = pin / 10;
a += (pin % 10);
pin = pin / 10;
}

return (10 - (a % 10)) % 10;
}


int get_wps_pin_from_mac(struct sigma_dut *dut, const char *macaddr,
char *pin, size_t len)
{
unsigned char mac[ETH_ALEN];
int tmp, checksum;

if (len < 9)
return -1;
if (parse_mac_address(dut, macaddr, mac))
return -1;

/*
* get 7 digit PIN from the last 24 bits of MAC
* range 1000000 - 9999999
*/
tmp = (mac[5] & 0xFF) | ((mac[4] & 0xFF) << 8) |
((mac[3] & 0xFF) << 16);
tmp = (tmp % 9000000) + 1000000;
checksum = get_wps_pin_checksum(tmp);
snprintf(pin, len, "%07d%01d", tmp, checksum);
return 0;
}


void str_remove_chars(char *str, char ch)
{
char *pr = str, *pw = str;
Expand Down

0 comments on commit 0dae51c

Please sign in to comment.