Interworking: Use generic language,string parser

Replace the Venue Name specific data structure and parser with a
generic mechanism that can be used with other fields that use the
same format.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-08-25 20:49:30 +03:00
parent 4065a3092b
commit 1792e58dbb
3 changed files with 31 additions and 24 deletions

View file

@ -1289,45 +1289,52 @@ static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
} }
static int parse_venue_name(struct hostapd_bss_config *bss, char *pos, static int parse_lang_string(struct hostapd_lang_string **array,
int line) unsigned int *count, char *pos)
{ {
char *sep; char *sep;
size_t clen, nlen; size_t clen, nlen;
struct hostapd_venue_name *vn; struct hostapd_lang_string *ls;
sep = os_strchr(pos, ':'); sep = os_strchr(pos, ':');
if (sep == NULL) if (sep == NULL)
goto fail; return -1;
*sep++ = '\0'; *sep++ = '\0';
clen = os_strlen(pos); clen = os_strlen(pos);
if (clen < 2) if (clen < 2)
goto fail; return -1;
nlen = os_strlen(sep); nlen = os_strlen(sep);
if (nlen > 252) if (nlen > 252)
goto fail;
vn = os_realloc_array(bss->venue_name, bss->venue_name_count + 1,
sizeof(struct hostapd_venue_name));
if (vn == NULL)
return -1; return -1;
bss->venue_name = vn; ls = os_realloc_array(*array, *count + 1,
vn = &bss->venue_name[bss->venue_name_count]; sizeof(struct hostapd_lang_string));
bss->venue_name_count++; if (ls == NULL)
return -1;
os_memset(vn->lang, 0, sizeof(vn->lang)); *array = ls;
os_memcpy(vn->lang, pos, clen); ls = &(*array)[*count];
vn->name_len = nlen; (*count)++;
os_memcpy(vn->name, sep, nlen);
os_memset(ls->lang, 0, sizeof(ls->lang));
os_memcpy(ls->lang, pos, clen);
ls->name_len = nlen;
os_memcpy(ls->name, sep, nlen);
return 0; return 0;
}
fail:
wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'", static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
line, pos); int line)
return -1; {
if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
line, pos);
return -1;
}
return 0;
} }

View file

@ -145,7 +145,7 @@ struct hostapd_roaming_consortium {
u8 oi[MAX_ROAMING_CONSORTIUM_LEN]; u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
}; };
struct hostapd_venue_name { struct hostapd_lang_string {
u8 lang[3]; u8 lang[3];
u8 name_len; u8 name_len;
u8 name[252]; u8 name[252];
@ -386,7 +386,7 @@ struct hostapd_bss_config {
/* IEEE 802.11u - Venue Name duples */ /* IEEE 802.11u - Venue Name duples */
unsigned int venue_name_count; unsigned int venue_name_count;
struct hostapd_venue_name *venue_name; struct hostapd_lang_string *venue_name;
/* IEEE 802.11u - Network Authentication Type */ /* IEEE 802.11u - Network Authentication Type */
u8 *network_auth_type; u8 *network_auth_type;

View file

@ -182,7 +182,7 @@ static void anqp_add_venue_name(struct hostapd_data *hapd, struct wpabuf *buf)
wpabuf_put_u8(buf, hapd->conf->venue_group); wpabuf_put_u8(buf, hapd->conf->venue_group);
wpabuf_put_u8(buf, hapd->conf->venue_type); wpabuf_put_u8(buf, hapd->conf->venue_type);
for (i = 0; i < hapd->conf->venue_name_count; i++) { for (i = 0; i < hapd->conf->venue_name_count; i++) {
struct hostapd_venue_name *vn; struct hostapd_lang_string *vn;
vn = &hapd->conf->venue_name[i]; vn = &hapd->conf->venue_name[i];
wpabuf_put_u8(buf, 3 + vn->name_len); wpabuf_put_u8(buf, 3 + vn->name_len);
wpabuf_put_data(buf, vn->lang, 3); wpabuf_put_data(buf, vn->lang, 3);