2829
static int wpa_driver_test_p2p_find(void *priv, unsigned int timeout, int type)
2831
struct wpa_driver_test_data *drv = priv;
2832
wpa_printf(MSG_DEBUG, "%s(timeout=%u)", __func__, timeout);
2835
return p2p_find(drv->p2p, timeout, type, 0, NULL, NULL);
2839
static int wpa_driver_test_p2p_stop_find(void *priv)
2841
struct wpa_driver_test_data *drv = priv;
2842
wpa_printf(MSG_DEBUG, "%s", __func__);
2845
p2p_stop_find(drv->p2p);
2850
static int wpa_driver_test_p2p_listen(void *priv, unsigned int timeout)
2852
struct wpa_driver_test_data *drv = priv;
2853
wpa_printf(MSG_DEBUG, "%s(timeout=%u)", __func__, timeout);
2856
return p2p_listen(drv->p2p, timeout);
2860
static int wpa_driver_test_p2p_connect(void *priv, const u8 *peer_addr,
2861
int wps_method, int go_intent,
2862
const u8 *own_interface_addr,
2863
unsigned int force_freq,
2864
int persistent_group)
2866
struct wpa_driver_test_data *drv = priv;
2867
wpa_printf(MSG_DEBUG, "%s(peer_addr=" MACSTR " wps_method=%d "
2869
"own_interface_addr=" MACSTR " force_freq=%u "
2870
"persistent_group=%d)",
2871
__func__, MAC2STR(peer_addr), wps_method, go_intent,
2872
MAC2STR(own_interface_addr), force_freq, persistent_group);
2875
return p2p_connect(drv->p2p, peer_addr, wps_method, go_intent,
2876
own_interface_addr, force_freq, persistent_group);
2880
static int wpa_driver_test_wps_success_cb(void *priv, const u8 *peer_addr)
2882
struct wpa_driver_test_data *drv = priv;
2883
wpa_printf(MSG_DEBUG, "%s(peer_addr=" MACSTR ")",
2884
__func__, MAC2STR(peer_addr));
2887
p2p_wps_success_cb(drv->p2p, peer_addr);
2892
static int wpa_driver_test_p2p_group_formation_failed(void *priv)
2894
struct wpa_driver_test_data *drv = priv;
2895
wpa_printf(MSG_DEBUG, "%s", __func__);
2898
p2p_group_formation_failed(drv->p2p);
2903
static int wpa_driver_test_p2p_set_params(void *priv,
2904
const struct p2p_params *params)
2906
struct wpa_driver_test_data *drv = priv;
2907
wpa_printf(MSG_DEBUG, "%s", __func__);
2910
if (p2p_set_dev_name(drv->p2p, params->dev_name) < 0 ||
2911
p2p_set_pri_dev_type(drv->p2p, params->pri_dev_type) < 0 ||
2912
p2p_set_sec_dev_types(drv->p2p, params->sec_dev_type,
2913
params->num_sec_dev_types) < 0)
2919
static int test_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
2920
unsigned int num_req_dev_types,
2921
const u8 *req_dev_types, const u8 *dev_id)
2923
struct wpa_driver_test_data *drv = ctx;
2924
struct wpa_driver_scan_params params;
2926
struct wpabuf *wps_ie, *ies;
2927
int social_channels[] = { 2412, 2437, 2462, 0, 0 };
2930
wpa_printf(MSG_DEBUG, "%s(type=%d freq=%d)",
2931
__func__, type, freq);
2933
os_memset(¶ms, 0, sizeof(params));
2935
/* P2P Wildcard SSID */
2936
params.num_ssids = 1;
2937
params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
2938
params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
2940
#if 0 /* TODO: WPS IE */
2941
wpa_s->wps->dev.p2p = 1;
2942
wps_ie = wps_build_probe_req_ie(0, &wpa_s->wps->dev, wpa_s->wps->uuid,
2945
wps_ie = wpabuf_alloc(1);
2950
ielen = p2p_scan_ie_buf_len(drv->p2p);
2951
ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
2953
wpabuf_free(wps_ie);
2956
wpabuf_put_buf(ies, wps_ie);
2957
wpabuf_free(wps_ie);
2959
p2p_scan_ie(drv->p2p, ies, dev_id);
2961
params.extra_ies = wpabuf_head(ies);
2962
params.extra_ies_len = wpabuf_len(ies);
2965
case P2P_SCAN_SOCIAL:
2966
params.freqs = social_channels;
2970
case P2P_SCAN_SPECIFIC:
2971
social_channels[0] = freq;
2972
social_channels[1] = 0;
2973
params.freqs = social_channels;
2975
case P2P_SCAN_SOCIAL_PLUS_ONE:
2976
social_channels[3] = freq;
2977
params.freqs = social_channels;
2981
drv->pending_p2p_scan = 1;
2982
ret = wpa_driver_test_scan(drv, ¶ms);
2990
static int test_send_action(void *ctx, unsigned int freq, const u8 *dst,
2991
const u8 *src, const u8 *bssid, const u8 *buf,
2992
size_t len, unsigned int wait_time)
2994
struct wpa_driver_test_data *drv = ctx;
2996
wpa_printf(MSG_DEBUG, "%s(freq=%u dst=" MACSTR " src=" MACSTR
2997
" bssid=" MACSTR " len=%d",
2998
__func__, freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
3001
wpa_printf(MSG_WARNING, "P2P: No frequency specified for "
3006
if (drv->pending_action_tx) {
3007
wpa_printf(MSG_DEBUG, "P2P: Dropped pending Action frame TX "
3008
"to " MACSTR, MAC2STR(drv->pending_action_dst));
3009
wpabuf_free(drv->pending_action_tx);
3011
drv->pending_action_tx = wpabuf_alloc(len);
3012
if (drv->pending_action_tx == NULL)
3014
wpabuf_put_data(drv->pending_action_tx, buf, len);
3015
os_memcpy(drv->pending_action_src, src, ETH_ALEN);
3016
os_memcpy(drv->pending_action_dst, dst, ETH_ALEN);
3017
os_memcpy(drv->pending_action_bssid, bssid, ETH_ALEN);
3018
drv->pending_action_freq = freq;
3019
drv->pending_action_no_cck = 1;
3021
if (drv->off_channel_freq == freq) {
3022
/* Already on requested channel; send immediately */
3023
/* TODO: Would there ever be need to extend the current
3024
* duration on the channel? */
3025
eloop_cancel_timeout(test_send_action_cb, drv, NULL);
3026
eloop_register_timeout(0, 0, test_send_action_cb, drv, NULL);
3030
wpa_printf(MSG_DEBUG, "P2P: Schedule Action frame to be transmitted "
3031
"once the driver gets to the requested channel");
3032
if (wpa_driver_test_remain_on_channel(drv, freq, wait_time) < 0) {
3033
wpa_printf(MSG_DEBUG, "P2P: Failed to request driver "
3034
"to remain on channel (%u MHz) for Action "
3043
static void test_send_action_done(void *ctx)
3045
wpa_printf(MSG_DEBUG, "%s", __func__);
3050
static void test_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
3052
struct wpa_driver_test_data *drv = ctx;
3053
union wpa_event_data event;
3054
wpa_printf(MSG_DEBUG, "%s", __func__);
3055
os_memset(&event, 0, sizeof(event));
3056
event.p2p_go_neg_completed.res = res;
3057
wpa_supplicant_event(drv->ctx, EVENT_P2P_GO_NEG_COMPLETED, &event);
3061
static void test_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id)
3063
struct wpa_driver_test_data *drv = ctx;
3064
union wpa_event_data event;
3065
wpa_printf(MSG_DEBUG, "%s(src=" MACSTR ")", __func__, MAC2STR(src));
3066
os_memset(&event, 0, sizeof(event));
3067
event.p2p_go_neg_req_rx.src = src;
3068
event.p2p_go_neg_req_rx.dev_passwd_id = dev_passwd_id;
3069
wpa_supplicant_event(drv->ctx, EVENT_P2P_GO_NEG_REQ_RX, &event);
3073
static void test_dev_found(void *ctx, const u8 *addr,
3074
const struct p2p_peer_info *info, int new_device)
3076
struct wpa_driver_test_data *drv = ctx;
3077
union wpa_event_data event;
3078
char devtype[WPS_DEV_TYPE_BUFSIZE];
3079
wpa_printf(MSG_DEBUG, "%s(" MACSTR " p2p_dev_addr=" MACSTR
3080
" pri_dev_type=%s name='%s' config_methods=0x%x "
3081
"dev_capab=0x%x group_capab=0x%x)",
3082
__func__, MAC2STR(addr), MAC2STR(info->p2p_device_addr),
3083
wps_dev_type_bin2str(info->pri_dev_type, devtype,
3085
info->device_name, info->config_methods, info->dev_capab,
3088
os_memset(&event, 0, sizeof(event));
3089
event.p2p_dev_found.addr = addr;
3090
event.p2p_dev_found.dev_addr = info->p2p_device_addr;
3091
event.p2p_dev_found.pri_dev_type = info->pri_dev_type;
3092
event.p2p_dev_found.dev_name = info->device_name;
3093
event.p2p_dev_found.config_methods = info->config_methods;
3094
event.p2p_dev_found.dev_capab = info->dev_capab;
3095
event.p2p_dev_found.group_capab = info->group_capab;
3096
wpa_supplicant_event(drv->ctx, EVENT_P2P_DEV_FOUND, &event);
3100
static int test_start_listen(void *ctx, unsigned int freq,
3101
unsigned int duration,
3102
const struct wpabuf *probe_resp_ie)
3104
struct wpa_driver_test_data *drv = ctx;
3106
wpa_printf(MSG_DEBUG, "%s(freq=%u duration=%u)",
3107
__func__, freq, duration);
3109
if (wpa_driver_test_probe_req_report(drv, 1) < 0)
3112
drv->pending_listen_freq = freq;
3113
drv->pending_listen_duration = duration;
3115
if (wpa_driver_test_remain_on_channel(drv, freq, duration) < 0) {
3116
drv->pending_listen_freq = 0;
3124
static void test_stop_listen(void *ctx)
3126
wpa_printf(MSG_DEBUG, "%s", __func__);
3131
static int test_send_probe_resp(void *ctx, const struct wpabuf *buf)
3133
struct wpa_driver_test_data *drv = ctx;
3134
char resp[512], *pos, *end;
3136
const struct ieee80211_mgmt *mgmt;
3137
const u8 *ie, *ie_end;
3139
wpa_printf(MSG_DEBUG, "%s", __func__);
3140
wpa_hexdump_buf(MSG_MSGDUMP, "Probe Response", buf);
3141
if (wpabuf_len(buf) < 24)
3143
if (!drv->probe_from) {
3144
wpa_printf(MSG_DEBUG, "%s: probe_from not set", __func__);
3149
end = resp + sizeof(resp);
3151
mgmt = wpabuf_head(buf);
3153
/* reply: SCANRESP BSSID SSID IEs */
3154
ret = os_snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
3155
MAC2STR(mgmt->bssid));
3156
if (ret < 0 || ret >= end - pos)
3160
ie = mgmt->u.probe_resp.variable;
3161
ie_end = wpabuf_head_u8(buf) + wpabuf_len(buf);
3162
if (ie_end - ie < 2 || ie[0] != WLAN_EID_SSID ||
3163
ie + 2 + ie[1] > ie_end)
3165
pos += wpa_snprintf_hex(pos, end - pos, ie + 2, ie[1]);
3167
ret = os_snprintf(pos, end - pos, " ");
3168
if (ret < 0 || ret >= end - pos)
3171
pos += wpa_snprintf_hex(pos, end - pos, ie, ie_end - ie);
3173
sendto(drv->test_socket, resp, pos - resp, 0,
3174
drv->probe_from, drv->probe_from_len);
3180
static void test_sd_request(void *ctx, int freq, const u8 *sa, u8 dialog_token,
3181
u16 update_indic, const u8 *tlvs, size_t tlvs_len)
3183
wpa_printf(MSG_DEBUG, "%s", __func__);
3188
static void test_sd_response(void *ctx, const u8 *sa, u16 update_indic,
3189
const u8 *tlvs, size_t tlvs_len)
3191
wpa_printf(MSG_DEBUG, "%s", __func__);
3196
static void test_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
3197
const u8 *dev_addr, const u8 *pri_dev_type,
3198
const char *dev_name, u16 supp_config_methods,
3199
u8 dev_capab, u8 group_capab,
3200
const u8 *group_id, size_t group_id_len)
3202
wpa_printf(MSG_DEBUG, "%s(peer=" MACSTR " config_methods=0x%x)",
3203
__func__, MAC2STR(peer), config_methods);
3208
static void test_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
3210
wpa_printf(MSG_DEBUG, "%s(peer=" MACSTR " config_methods=0x%x)",
3211
__func__, MAC2STR(peer), config_methods);
3215
#endif /* CONFIG_P2P */
3218
static int wpa_driver_test_init_p2p(struct wpa_driver_test_data *drv)
3221
struct p2p_config p2p;
3225
os_memset(&p2p, 0, sizeof(p2p));
3226
p2p.msg_ctx = drv->ctx;
3228
p2p.p2p_scan = test_p2p_scan;
3229
p2p.send_action = test_send_action;
3230
p2p.send_action_done = test_send_action_done;
3231
p2p.go_neg_completed = test_go_neg_completed;
3232
p2p.go_neg_req_rx = test_go_neg_req_rx;
3233
p2p.dev_found = test_dev_found;
3234
p2p.start_listen = test_start_listen;
3235
p2p.stop_listen = test_stop_listen;
3236
p2p.send_probe_resp = test_send_probe_resp;
3237
p2p.sd_request = test_sd_request;
3238
p2p.sd_response = test_sd_response;
3239
p2p.prov_disc_req = test_prov_disc_req;
3240
p2p.prov_disc_resp = test_prov_disc_resp;
3242
os_memcpy(p2p.dev_addr, drv->own_addr, ETH_ALEN);
3244
p2p.reg_class = 12; /* TODO: change depending on location */
3246
* Pick one of the social channels randomly as the listen
3249
os_get_random((u8 *) &r, sizeof(r));
3250
p2p.channel = 1 + (r % 3) * 5;
3252
/* TODO: change depending on location */
3253
p2p.op_reg_class = 12;
3255
* For initial tests, pick the operation channel randomly.
3256
* TODO: Use scan results (etc.) to select the best channel.
3258
p2p.op_channel = 1 + r % 11;
3260
os_memcpy(p2p.country, "US ", 3);
3262
/* FIX: fetch available channels from the driver */
3263
p2p.channels.reg_classes = 1;
3264
p2p.channels.reg_class[0].reg_class = 12; /* US/12 = 2.4 GHz band */
3265
p2p.channels.reg_class[0].channels = 11;
3266
for (i = 0; i < 11; i++)
3267
p2p.channels.reg_class[0].channel[i] = i + 1;
3269
p2p.max_peers = 100;
3271
drv->p2p = p2p_init(&p2p);
3272
if (drv->p2p == NULL)
3275
#else /* CONFIG_P2P */
3276
wpa_printf(MSG_INFO, "driver_test: P2P support not included");
3278
#endif /* CONFIG_P2P */
3282
2637
const struct wpa_driver_ops wpa_driver_test_ops = {
3284
2639
"wpa_supplicant test driver",