WPS: Moved Version attribute validation into a shared function

This commit is contained in:
Jouni Malinen 2009-02-06 14:15:47 +02:00 committed by Jouni Malinen
parent fda90ab4b7
commit f65cbff3a3
3 changed files with 19 additions and 11 deletions

View file

@ -956,7 +956,7 @@ static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
if (attr.version == NULL || *attr.version != WPS_VERSION) {
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
attr.version ? *attr.version : 0);
return WPS_FAILURE;
@ -1029,7 +1029,7 @@ static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
if (attr.version == NULL || *attr.version != WPS_VERSION) {
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
attr.version ? *attr.version : 0);
return WPS_FAILURE;
@ -1081,7 +1081,7 @@ static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
if (attr.version == NULL || *attr.version != WPS_VERSION) {
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
attr.version ? *attr.version : 0);
return WPS_FAILURE;

View file

@ -238,4 +238,10 @@ enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
enum wsc_op_code op_code,
const struct wpabuf *msg);
static inline int wps_version_supported(const u8 *version)
{
return version && *version == WPS_VERSION;
}
#endif /* WPS_I_H */

View file

@ -602,8 +602,9 @@ void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
"WPS: Probe Request with WPS data received",
wps_data);
if (wps_parse_msg(wps_data, &attr) < 0 ||
attr.version == NULL || *attr.version != WPS_VERSION) {
if (wps_parse_msg(wps_data, &attr) < 0)
return;
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported ProbeReq WPS IE "
"version 0x%x", attr.version ? *attr.version : 0);
return;
@ -1933,7 +1934,7 @@ static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
if (attr.version == NULL || *attr.version != WPS_VERSION) {
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
attr.version ? *attr.version : 0);
return WPS_FAILURE;
@ -2009,7 +2010,7 @@ static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
if (attr.version == NULL || *attr.version != WPS_VERSION) {
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
attr.version ? *attr.version : 0);
return WPS_FAILURE;
@ -2084,7 +2085,7 @@ static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
if (attr.version == NULL || *attr.version != WPS_VERSION) {
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
attr.version ? *attr.version : 0);
return WPS_FAILURE;
@ -2169,7 +2170,7 @@ static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
if (attr.version == NULL || *attr.version != WPS_VERSION) {
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
attr.version ? *attr.version : 0);
return WPS_FAILURE;
@ -2360,8 +2361,9 @@ int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
msg);
if (wps_parse_msg(msg, &attr) < 0 ||
attr.version == NULL || *attr.version != WPS_VERSION) {
if (wps_parse_msg(msg, &attr) < 0)
return -1;
if (!wps_version_supported(attr.version)) {
wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
"version 0x%x", attr.version ? *attr.version : 0);
return -1;