WPS UFD: Remove oob_dev pointer from wps_context
This pointer and the especially the oob_dev->device_path does not remain valid, so better not save it any longer than it is needed.
This commit is contained in:
parent
1b39bad109
commit
7cbf51bbd8
5 changed files with 24 additions and 26 deletions
|
@ -713,14 +713,15 @@ int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type,
|
|||
char *path, char *method)
|
||||
{
|
||||
struct wps_context *wps = hapd->wps;
|
||||
struct oob_device_data *oob_dev;
|
||||
|
||||
wps->oob_dev = wps_get_oob_device(device_type);
|
||||
if (wps->oob_dev == NULL)
|
||||
oob_dev = wps_get_oob_device(device_type);
|
||||
if (oob_dev == NULL)
|
||||
return -1;
|
||||
wps->oob_dev->device_path = path;
|
||||
oob_dev->device_path = path;
|
||||
wps->oob_conf.oob_method = wps_get_oob_method(method);
|
||||
|
||||
if (wps_process_oob(wps, 1) < 0)
|
||||
if (wps_process_oob(wps, oob_dev, 1) < 0)
|
||||
return -1;
|
||||
|
||||
if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
|
||||
|
|
|
@ -408,11 +408,6 @@ struct wps_context {
|
|||
*/
|
||||
struct wps_device_data dev;
|
||||
|
||||
/**
|
||||
* oob_dev - OOB Device data
|
||||
*/
|
||||
struct oob_device_data *oob_dev;
|
||||
|
||||
/**
|
||||
* oob_conf - OOB Config data
|
||||
*/
|
||||
|
@ -532,7 +527,8 @@ struct wps_context {
|
|||
|
||||
struct oob_device_data {
|
||||
char *device_path;
|
||||
void * (*init_func)(struct wps_context *, int);
|
||||
void * (*init_func)(struct wps_context *, struct oob_device_data *,
|
||||
int);
|
||||
struct wpabuf * (*read_func)(void *);
|
||||
int (*write_func)(void *, struct wpabuf *);
|
||||
void (*deinit_func)(void *);
|
||||
|
@ -560,6 +556,7 @@ void wps_free_pending_msgs(struct upnp_pending_message *msgs);
|
|||
|
||||
struct oob_device_data * wps_get_oob_device(char *device_type);
|
||||
int wps_get_oob_method(char *method);
|
||||
int wps_process_oob(struct wps_context *wps, int registrar);
|
||||
int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
|
||||
int registrar);
|
||||
|
||||
#endif /* WPS_H */
|
||||
|
|
|
@ -468,16 +468,16 @@ static int wps_parse_oob_cred(struct wps_context *wps, struct wpabuf *data)
|
|||
}
|
||||
|
||||
|
||||
int wps_process_oob(struct wps_context *wps, int registrar)
|
||||
int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
|
||||
int registrar)
|
||||
{
|
||||
struct oob_device_data *oob_dev = wps->oob_dev;
|
||||
struct wpabuf *data;
|
||||
int ret, write_f, oob_method = wps->oob_conf.oob_method;
|
||||
void *oob_priv;
|
||||
|
||||
write_f = oob_method == OOB_METHOD_DEV_PWD_E ? !registrar : registrar;
|
||||
|
||||
oob_priv = oob_dev->init_func(wps, registrar);
|
||||
oob_priv = oob_dev->init_func(wps, oob_dev, registrar);
|
||||
if (oob_priv == NULL) {
|
||||
wpa_printf(MSG_ERROR, "WPS: Failed to initialize OOB device");
|
||||
return -1;
|
||||
|
@ -490,8 +490,7 @@ int wps_process_oob(struct wps_context *wps, int registrar)
|
|||
data = wps_get_oob_dev_pwd(wps);
|
||||
|
||||
ret = 0;
|
||||
if (data == NULL ||
|
||||
wps->oob_dev->write_func(oob_priv, data) < 0)
|
||||
if (data == NULL || oob_dev->write_func(oob_priv, data) < 0)
|
||||
ret = -1;
|
||||
} else {
|
||||
data = oob_dev->read_func(oob_priv);
|
||||
|
|
|
@ -80,7 +80,7 @@ static int wps_get_dev_pwd_e_file_name(char *path, char *file_name)
|
|||
|
||||
|
||||
static int get_file_name(struct wps_context *wps, int registrar,
|
||||
char *file_name)
|
||||
const char *path, char *file_name)
|
||||
{
|
||||
switch (wps->oob_conf.oob_method) {
|
||||
case OOB_METHOD_CRED:
|
||||
|
@ -89,8 +89,7 @@ static int get_file_name(struct wps_context *wps, int registrar,
|
|||
case OOB_METHOD_DEV_PWD_E:
|
||||
if (registrar) {
|
||||
char temp[128];
|
||||
os_snprintf(temp, sizeof(temp), UFD_DIR2,
|
||||
wps->oob_dev->device_path);
|
||||
os_snprintf(temp, sizeof(temp), UFD_DIR2, path);
|
||||
if (wps_get_dev_pwd_e_file_name(temp, file_name) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -123,11 +122,12 @@ static int ufd_mkdir(const char *path)
|
|||
}
|
||||
|
||||
|
||||
static void * init_ufd(struct wps_context *wps, int registrar)
|
||||
static void * init_ufd(struct wps_context *wps,
|
||||
struct oob_device_data *oob_dev, int registrar)
|
||||
{
|
||||
int write_f;
|
||||
char temp[128];
|
||||
char *path = wps->oob_dev->device_path;
|
||||
char *path = oob_dev->device_path;
|
||||
char filename[13];
|
||||
struct wps_ufd_data *data;
|
||||
int ufd_fd;
|
||||
|
@ -138,7 +138,7 @@ static void * init_ufd(struct wps_context *wps, int registrar)
|
|||
write_f = wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ?
|
||||
!registrar : registrar;
|
||||
|
||||
if (get_file_name(wps, registrar, filename) < 0) {
|
||||
if (get_file_name(wps, registrar, path, filename) < 0) {
|
||||
wpa_printf(MSG_ERROR, "WPS (UFD): Failed to get file name");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -466,17 +466,18 @@ int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
|
|||
char *path, char *method)
|
||||
{
|
||||
struct wps_context *wps = wpa_s->wps;
|
||||
struct oob_device_data *oob_dev;
|
||||
|
||||
wps->oob_dev = wps_get_oob_device(device_type);
|
||||
if (wps->oob_dev == NULL)
|
||||
oob_dev = wps_get_oob_device(device_type);
|
||||
if (oob_dev == NULL)
|
||||
return -1;
|
||||
wps->oob_dev->device_path = path;
|
||||
oob_dev->device_path = path;
|
||||
wps->oob_conf.oob_method = wps_get_oob_method(method);
|
||||
|
||||
if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
|
||||
wpas_clear_wps(wpa_s);
|
||||
|
||||
if (wps_process_oob(wps, 0) < 0)
|
||||
if (wps_process_oob(wps, oob_dev, 0) < 0)
|
||||
return -1;
|
||||
|
||||
if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
|
||||
|
|
Loading…
Reference in a new issue