WPS: Remove unnecessary GetDevice and PutMessage callbacks
These callbacks can be handled internally within core WPS code, so there is no need to go through wps_hostapd.c with a callback function that is just calling back into the core WPS code.
This commit is contained in:
parent
d0d45d8276
commit
5e9c730a2b
4 changed files with 40 additions and 68 deletions
|
@ -805,61 +805,6 @@ static void hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
|
||||||
|
|
||||||
#ifdef CONFIG_WPS_UPNP
|
#ifdef CONFIG_WPS_UPNP
|
||||||
|
|
||||||
static struct wpabuf *
|
|
||||||
hostapd_rx_req_get_device_info(void *priv, struct upnp_wps_peer *peer)
|
|
||||||
{
|
|
||||||
struct hostapd_data *hapd = priv;
|
|
||||||
struct wps_config cfg;
|
|
||||||
struct wps_data *wps;
|
|
||||||
enum wsc_op_code op_code;
|
|
||||||
struct wpabuf *m1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS
|
|
||||||
* registration over UPnP with the AP acting as an Enrollee. It should
|
|
||||||
* be noted that this is frequently used just to get the device data,
|
|
||||||
* i.e., there may not be any intent to actually complete the
|
|
||||||
* registration.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (peer->wps)
|
|
||||||
wps_deinit(peer->wps);
|
|
||||||
|
|
||||||
os_memset(&cfg, 0, sizeof(cfg));
|
|
||||||
cfg.wps = hapd->wps;
|
|
||||||
cfg.pin = (u8 *) hapd->conf->ap_pin;
|
|
||||||
cfg.pin_len = os_strlen(hapd->conf->ap_pin);
|
|
||||||
wps = wps_init(&cfg);
|
|
||||||
if (wps == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
m1 = wps_get_msg(wps, &op_code);
|
|
||||||
if (m1 == NULL) {
|
|
||||||
wps_deinit(wps);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
peer->wps = wps;
|
|
||||||
|
|
||||||
return m1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static struct wpabuf *
|
|
||||||
hostapd_rx_req_put_message(void *priv, struct upnp_wps_peer *peer,
|
|
||||||
const struct wpabuf *msg)
|
|
||||||
{
|
|
||||||
enum wps_process_res res;
|
|
||||||
enum wsc_op_code op_code;
|
|
||||||
|
|
||||||
/* PutMessage: msg = InMessage, return OutMessage */
|
|
||||||
res = wps_process_msg(peer->wps, WSC_UPnP, msg);
|
|
||||||
if (res == WPS_FAILURE)
|
|
||||||
return NULL;
|
|
||||||
return wps_get_msg(peer->wps, &op_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int hostapd_rx_req_put_wlan_response(
|
static int hostapd_rx_req_put_wlan_response(
|
||||||
void *priv, enum upnp_wps_wlanevent_type ev_type,
|
void *priv, enum upnp_wps_wlanevent_type ev_type,
|
||||||
const u8 *mac_addr, const struct wpabuf *msg,
|
const u8 *mac_addr, const struct wpabuf *msg,
|
||||||
|
@ -928,9 +873,9 @@ static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ctx->rx_req_get_device_info = hostapd_rx_req_get_device_info;
|
|
||||||
ctx->rx_req_put_message = hostapd_rx_req_put_message;
|
|
||||||
ctx->rx_req_put_wlan_response = hostapd_rx_req_put_wlan_response;
|
ctx->rx_req_put_wlan_response = hostapd_rx_req_put_wlan_response;
|
||||||
|
if (hapd->conf->ap_pin)
|
||||||
|
ctx->ap_pin = os_strdup(hapd->conf->ap_pin);
|
||||||
|
|
||||||
hapd->wps_upnp = upnp_wps_device_init(ctx, wps, hapd);
|
hapd->wps_upnp = upnp_wps_device_init(ctx, wps, hapd);
|
||||||
if (hapd->wps_upnp == NULL) {
|
if (hapd->wps_upnp == NULL) {
|
||||||
|
|
|
@ -1101,6 +1101,7 @@ void upnp_wps_device_deinit(struct upnp_wps_device_sm *sm)
|
||||||
wps_deinit(sm->peer.wps);
|
wps_deinit(sm->peer.wps);
|
||||||
os_free(sm->root_dir);
|
os_free(sm->root_dir);
|
||||||
os_free(sm->desc_url);
|
os_free(sm->desc_url);
|
||||||
|
os_free(sm->ctx->ap_pin);
|
||||||
os_free(sm->ctx);
|
os_free(sm->ctx);
|
||||||
os_free(sm);
|
os_free(sm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ enum upnp_wps_wlanevent_type {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct upnp_wps_device_ctx {
|
struct upnp_wps_device_ctx {
|
||||||
struct wpabuf * (*rx_req_get_device_info)(
|
|
||||||
void *priv, struct upnp_wps_peer *peer);
|
|
||||||
struct wpabuf * (*rx_req_put_message)(
|
|
||||||
void *priv, struct upnp_wps_peer *peer,
|
|
||||||
const struct wpabuf *msg);
|
|
||||||
int (*rx_req_put_wlan_response)(
|
int (*rx_req_put_wlan_response)(
|
||||||
void *priv, enum upnp_wps_wlanevent_type ev_type,
|
void *priv, enum upnp_wps_wlanevent_type ev_type,
|
||||||
const u8 *mac_addr, const struct wpabuf *msg,
|
const u8 *mac_addr, const struct wpabuf *msg,
|
||||||
enum wps_msg_type msg_type);
|
enum wps_msg_type msg_type);
|
||||||
|
|
||||||
|
char *ap_pin;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct upnp_wps_device_sm *
|
struct upnp_wps_device_sm *
|
||||||
|
|
|
@ -407,11 +407,36 @@ web_process_get_device_info(struct upnp_wps_device_sm *sm,
|
||||||
struct wpabuf **reply, const char **replyname)
|
struct wpabuf **reply, const char **replyname)
|
||||||
{
|
{
|
||||||
static const char *name = "NewDeviceInfo";
|
static const char *name = "NewDeviceInfo";
|
||||||
|
struct wps_config cfg;
|
||||||
|
struct upnp_wps_peer *peer = &sm->peer;
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "WPS UPnP: GetDeviceInfo");
|
wpa_printf(MSG_DEBUG, "WPS UPnP: GetDeviceInfo");
|
||||||
if (sm->ctx->rx_req_get_device_info == NULL)
|
|
||||||
return HTTP_INTERNAL_SERVER_ERROR;
|
/*
|
||||||
*reply = sm->ctx->rx_req_get_device_info(sm->priv, &sm->peer);
|
* Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS
|
||||||
|
* registration over UPnP with the AP acting as an Enrollee. It should
|
||||||
|
* be noted that this is frequently used just to get the device data,
|
||||||
|
* i.e., there may not be any intent to actually complete the
|
||||||
|
* registration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (peer->wps)
|
||||||
|
wps_deinit(peer->wps);
|
||||||
|
|
||||||
|
os_memset(&cfg, 0, sizeof(cfg));
|
||||||
|
cfg.wps = sm->wps;
|
||||||
|
cfg.pin = (u8 *) sm->ctx->ap_pin;
|
||||||
|
cfg.pin_len = os_strlen(sm->ctx->ap_pin);
|
||||||
|
peer->wps = wps_init(&cfg);
|
||||||
|
if (peer->wps) {
|
||||||
|
enum wsc_op_code op_code;
|
||||||
|
*reply = wps_get_msg(peer->wps, &op_code);
|
||||||
|
if (*reply == NULL) {
|
||||||
|
wps_deinit(peer->wps);
|
||||||
|
peer->wps = NULL;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
*reply = NULL;
|
||||||
if (*reply == NULL) {
|
if (*reply == NULL) {
|
||||||
wpa_printf(MSG_INFO, "WPS UPnP: Failed to get DeviceInfo");
|
wpa_printf(MSG_INFO, "WPS UPnP: Failed to get DeviceInfo");
|
||||||
return HTTP_INTERNAL_SERVER_ERROR;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
@ -428,6 +453,8 @@ web_process_put_message(struct upnp_wps_device_sm *sm, char *data,
|
||||||
struct wpabuf *msg;
|
struct wpabuf *msg;
|
||||||
static const char *name = "NewOutMessage";
|
static const char *name = "NewOutMessage";
|
||||||
enum http_reply_code ret;
|
enum http_reply_code ret;
|
||||||
|
enum wps_process_res res;
|
||||||
|
enum wsc_op_code op_code;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PutMessage is used by external UPnP-based Registrar to perform WPS
|
* PutMessage is used by external UPnP-based Registrar to perform WPS
|
||||||
|
@ -435,12 +462,14 @@ web_process_put_message(struct upnp_wps_device_sm *sm, char *data,
|
||||||
* PutWLANResponse which is for proxying.
|
* PutWLANResponse which is for proxying.
|
||||||
*/
|
*/
|
||||||
wpa_printf(MSG_DEBUG, "WPS UPnP: PutMessage");
|
wpa_printf(MSG_DEBUG, "WPS UPnP: PutMessage");
|
||||||
if (sm->ctx->rx_req_put_message == NULL)
|
|
||||||
return HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
msg = xml_get_base64_item(data, "NewInMessage", &ret);
|
msg = xml_get_base64_item(data, "NewInMessage", &ret);
|
||||||
if (msg == NULL)
|
if (msg == NULL)
|
||||||
return ret;
|
return ret;
|
||||||
*reply = sm->ctx->rx_req_put_message(sm->priv, &sm->peer, msg);
|
res = wps_process_msg(sm->peer.wps, WSC_UPnP, msg);
|
||||||
|
if (res == WPS_FAILURE)
|
||||||
|
*reply = NULL;
|
||||||
|
else
|
||||||
|
*reply = wps_get_msg(sm->peer.wps, &op_code);
|
||||||
wpabuf_free(msg);
|
wpabuf_free(msg);
|
||||||
if (*reply == NULL)
|
if (*reply == NULL)
|
||||||
return HTTP_INTERNAL_SERVER_ERROR;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
|
Loading…
Add table
Reference in a new issue