mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-22 04:32:37 +01:00
p2putil: Add p2p_get_random_string
Add a utility to select random characters from the set defined in P2P v1.7 Section 3.2.1. In this version the assumption is that we're only actually using this for the two SSID characters.
This commit is contained in:
parent
fbb0776716
commit
116b36e943
@ -2611,3 +2611,36 @@ uint8_t *p2p_build_go_disc_req(size_t *out_len)
|
||||
return p2p_build_action_frame(false, P2P_ACTION_GO_DISCOVERABILITY_REQ,
|
||||
0, NULL, NULL, NULL, 0, out_len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Select a string of random characters from the set defined in section
|
||||
* 3.2.1:
|
||||
*
|
||||
* "Following "DIRECT-" the SSID shall contain two ASCII characters "xy",
|
||||
* randomly selected with a uniform distribution from the following
|
||||
* character set: upper case letters, lower case letters and numbers."
|
||||
*
|
||||
* "The WPA2-Personal pass-phrase shall contain at least eight ASCII
|
||||
* characters randomly selected with a uniform distribution from the
|
||||
* following character set: upper case letters, lower case letters and
|
||||
* numbers."
|
||||
*
|
||||
* Our random distribution is not uniform but close enough for use in
|
||||
* the SSID.
|
||||
*/
|
||||
void p2p_get_random_string(char *buf, size_t len)
|
||||
{
|
||||
#define CHARSET "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" \
|
||||
"0123456789"
|
||||
static const int set_size = strlen(CHARSET);
|
||||
|
||||
l_getrandom(buf, len);
|
||||
|
||||
while (len) {
|
||||
int index = *buf % set_size;
|
||||
|
||||
*buf++ = CHARSET[index];
|
||||
len--;
|
||||
}
|
||||
#undef CHARSET
|
||||
}
|
||||
|
@ -603,3 +603,5 @@ uint8_t *p2p_build_presence_req(const struct p2p_presence_req *data,
|
||||
uint8_t *p2p_build_presence_resp(const struct p2p_presence_resp *data,
|
||||
size_t *out_len);
|
||||
uint8_t *p2p_build_go_disc_req(size_t *out_len);
|
||||
|
||||
void p2p_get_random_string(char *buf, size_t len);
|
||||
|
Loading…
Reference in New Issue
Block a user