summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-02-05 17:45:56 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2014-02-05 17:45:56 +0100
commit7d06c9b9b4cac672df9cd7c594d4a5580c6c6d31 (patch)
treeecc0ca15a71855488b9a1d7cce8bf77c42c35306
parent62a0a0a10cc3a1c8679fdbc1a3a9720e80b45ad0 (diff)
wpa: add P2P-DEVICE-LOST parser
Add parser for P2P-DEVICE-LOST events so we can react on it. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r--src/libwfd.h5
-rw-r--r--src/wpa_parser.c27
-rw-r--r--test/test_wpa.c7
3 files changed, 39 insertions, 0 deletions
diff --git a/src/libwfd.h b/src/libwfd.h
index 834e4f1..c06475f 100644
--- a/src/libwfd.h
+++ b/src/libwfd.h
@@ -558,6 +558,7 @@ enum wfd_wpa_event_type {
WFD_WPA_EVENT_AP_STA_CONNECTED,
WFD_WPA_EVENT_AP_STA_DISCONNECTED,
WFD_WPA_EVENT_P2P_DEVICE_FOUND,
+ WFD_WPA_EVENT_P2P_DEVICE_LOST,
WFD_WPA_EVENT_P2P_FIND_STOPPED,
WFD_WPA_EVENT_P2P_GO_NEG_REQUEST,
WFD_WPA_EVENT_P2P_GO_NEG_SUCCESS,
@@ -612,6 +613,10 @@ struct wfd_wpa_event {
char *name;
} p2p_device_found;
+ struct wfd_wpa_event_p2p_device_lost {
+ char peer_mac[WFD_WPA_EVENT_MAC_STRLEN];
+ } p2p_device_lost;
+
struct wfd_wpa_event_p2p_go_neg_success {
char peer_mac[WFD_WPA_EVENT_MAC_STRLEN];
unsigned int role;
diff --git a/src/wpa_parser.c b/src/wpa_parser.c
index 567b851..9f98b5d 100644
--- a/src/wpa_parser.c
+++ b/src/wpa_parser.c
@@ -81,6 +81,7 @@ static const struct event_type {
EVENT("AP-STA-CONNECTED", AP_STA_CONNECTED),
EVENT("AP-STA-DISCONNECTED", AP_STA_DISCONNECTED),
EVENT("P2P-DEVICE-FOUND", P2P_DEVICE_FOUND),
+ EVENT("P2P-DEVICE-LOST", P2P_DEVICE_LOST),
EVENT("P2P-FIND-STOPPED", P2P_FIND_STOPPED),
EVENT("P2P-GO-NEG-FAILURE", P2P_GO_NEG_FAILURE),
EVENT("P2P-GO-NEG-REQUEST", P2P_GO_NEG_REQUEST),
@@ -271,6 +272,29 @@ static int parse_p2p_device_found(struct wfd_wpa_event *ev,
return -EINVAL;
}
+static int parse_p2p_device_lost(struct wfd_wpa_event *ev,
+ char *tokens, size_t num)
+{
+ int r;
+ size_t i;
+
+ if (num < 1)
+ return -EINVAL;
+
+ for (i = 0; i < num; ++i, tokens += strlen(tokens) + 1) {
+ if (strncmp(tokens, "p2p_dev_addr=", 13))
+ continue;
+
+ r = parse_mac(ev->p.p2p_device_lost.peer_mac, &tokens[13]);
+ if (r < 0)
+ return r;
+
+ return 0;
+ }
+
+ return 0;
+}
+
static int parse_p2p_go_neg_success(struct wfd_wpa_event *ev,
char *tokens, size_t num)
{
@@ -494,6 +518,9 @@ int wfd_wpa_event_parse(struct wfd_wpa_event *ev, const char *event)
case WFD_WPA_EVENT_P2P_DEVICE_FOUND:
r = parse_p2p_device_found(ev, tokens, num);
break;
+ case WFD_WPA_EVENT_P2P_DEVICE_LOST:
+ r = parse_p2p_device_lost(ev, tokens, num);
+ break;
case WFD_WPA_EVENT_P2P_GO_NEG_SUCCESS:
r = parse_p2p_go_neg_success(ev, tokens, num);
break;
diff --git a/test/test_wpa.c b/test/test_wpa.c
index afc98dc..7198ed7 100644
--- a/test/test_wpa.c
+++ b/test/test_wpa.c
@@ -40,6 +40,7 @@ static const char *event_list[] = {
[WFD_WPA_EVENT_AP_STA_CONNECTED] = "AP-STA-CONNECTED 00:00:00:00:00:00",
[WFD_WPA_EVENT_AP_STA_DISCONNECTED] = "AP-STA-DISCONNECTED 00:00:00:00:00:00",
[WFD_WPA_EVENT_P2P_DEVICE_FOUND] = "P2P-DEVICE-FOUND 00:00:00:00:00:00 name=some-name",
+ [WFD_WPA_EVENT_P2P_DEVICE_LOST] = "P2P-DEVICE-LOST p2p_dev_addr=00:00:00:00:00:00",
[WFD_WPA_EVENT_P2P_FIND_STOPPED] = "P2P-FIND-STOPPED",
[WFD_WPA_EVENT_P2P_GO_NEG_REQUEST] = "P2P-GO-NEG-REQUEST",
[WFD_WPA_EVENT_P2P_GO_NEG_SUCCESS] = "P2P-GO-NEG-SUCCESS role=GO peer_dev=00:00:00:00:00:00",
@@ -124,6 +125,12 @@ START_TEST(test_wpa_parser_payload)
ck_assert(!strcmp(ev.p.p2p_device_found.peer_mac, "0:0:0:0:0:0"));
ck_assert(!strcmp(ev.p.p2p_device_found.name, "some-name\\'"));
+ parse(&ev, "<4>P2P-DEVICE-LOST dummy=sth p2p_dev_addr=0:0:0:0:0:0");
+ ck_assert(ev.priority == WFD_WPA_EVENT_P_ERROR);
+ ck_assert(ev.type == WFD_WPA_EVENT_P2P_DEVICE_LOST);
+ ck_assert(ev.raw != NULL);
+ ck_assert(!strcmp(ev.p.p2p_device_lost.peer_mac, "0:0:0:0:0:0"));
+
parse(&ev, "<4>P2P-PROV-DISC-SHOW-PIN 0:0:0:0:0:0 1234567890");
ck_assert(ev.priority == WFD_WPA_EVENT_P_ERROR);
ck_assert(ev.type == WFD_WPA_EVENT_P2P_PROV_DISC_SHOW_PIN);