summaryrefslogtreecommitdiff
path: root/src/wpa.h
blob: af6c7438ecb6bce103f8cd8deda94b553d763ca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * OpenWFD - Open-Source Wifi-Display Implementation
 *
 * Copyright (c) 2013 David Herrmann <dh.herrmann@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef OWFD_WPA_H
#define OWFD_WPA_H

#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

/* wpa ctrl */

struct owfd_wpa_ctrl;

typedef void (*owfd_wpa_ctrl_cb) (struct owfd_wpa_ctrl *wpa, void *buf,
				  size_t len, void *data);

int owfd_wpa_ctrl_new(struct owfd_wpa_ctrl **out);
void owfd_wpa_ctrl_ref(struct owfd_wpa_ctrl *wpa);
void owfd_wpa_ctrl_unref(struct owfd_wpa_ctrl *wpa);

void owfd_wpa_ctrl_set_data(struct owfd_wpa_ctrl *wpa, void *data);
void *owfd_wpa_ctrl_get_data(struct owfd_wpa_ctrl *wpa);

int owfd_wpa_ctrl_open(struct owfd_wpa_ctrl *wpa, const char *ctrl_path,
		       owfd_wpa_ctrl_cb cb);
void owfd_wpa_ctrl_close(struct owfd_wpa_ctrl *wpa);
bool owfd_wpa_ctrl_is_open(struct owfd_wpa_ctrl *wpa);

int owfd_wpa_ctrl_get_fd(struct owfd_wpa_ctrl *wpa);
void owfd_wpa_ctrl_set_sigmask(struct owfd_wpa_ctrl *wpa,
			       const sigset_t *mask);
int owfd_wpa_ctrl_dispatch(struct owfd_wpa_ctrl *wpa, int timeout);

int owfd_wpa_ctrl_request(struct owfd_wpa_ctrl *wpa, const void *cmd,
			  size_t cmd_len, void *reply, size_t *reply_len,
			  int timeout);
int owfd_wpa_ctrl_request_ok(struct owfd_wpa_ctrl *wpa, const void *cmd,
			     size_t cmd_len, int timeout);

/* wpa parser */

enum owfd_wpa_event_type {
	OWFD_WPA_EVENT_UNKNOWN,
	OWFD_WPA_EVENT_AP_STA_CONNECTED,
	OWFD_WPA_EVENT_AP_STA_DISCONNECTED,
	OWFD_WPA_EVENT_P2P_DEVICE_FOUND,
	OWFD_WPA_EVENT_P2P_FIND_STOPPED,
	OWFD_WPA_EVENT_P2P_GO_NEG_REQUEST,
	OWFD_WPA_EVENT_P2P_GO_NEG_SUCCESS,
	OWFD_WPA_EVENT_P2P_GO_NEG_FAILURE,
	OWFD_WPA_EVENT_P2P_GROUP_FORMATION_SUCCESS,
	OWFD_WPA_EVENT_P2P_GROUP_FORMATION_FAILURE,
	OWFD_WPA_EVENT_P2P_GROUP_STARTED,
	OWFD_WPA_EVENT_P2P_GROUP_REMOVED,
	OWFD_WPA_EVENT_P2P_PROV_DISC_SHOW_PIN,
	OWFD_WPA_EVENT_P2P_PROV_DISC_ENTER_PIN,
	OWFD_WPA_EVENT_P2P_PROV_DISC_PBC_REQ,
	OWFD_WPA_EVENT_P2P_PROV_DISC_PBC_RESP,
	OWFD_WPA_EVENT_P2P_SERV_DISC_REQ,
	OWFD_WPA_EVENT_P2P_SERV_DISC_RESP,
	OWFD_WPA_EVENT_P2P_INVITATION_RECEIVED,
	OWFD_WPA_EVENT_P2P_INVITATION_RESULT,
	OWFD_WPA_EVENT_COUNT,
};

enum owfd_wpa_event_priority {
	OWFD_WPA_EVENT_P_MSGDUMP,
	OWFD_WPA_EVENT_P_DEBUG,
	OWFD_WPA_EVENT_P_INFO,
	OWFD_WPA_EVENT_P_WARNING,
	OWFD_WPA_EVENT_P_ERROR,
	OWFD_WPA_EVENT_P_COUNT
};

#define OWFD_WPA_EVENT_MAC_STRLEN 18

struct owfd_wpa_event {
	unsigned int type;
	unsigned int priority;
	char *raw;

	union owfd_wpa_event_payload {
		struct owfd_wpa_event_ap_sta_connected {
			char mac[OWFD_WPA_EVENT_MAC_STRLEN];
		} ap_sta_connected;
		struct owfd_wpa_event_ap_sta_disconnected {
			char mac[OWFD_WPA_EVENT_MAC_STRLEN];
		} ap_sta_disconnected;
		struct owfd_wpa_event_p2p_device_found {
			char peer_mac[OWFD_WPA_EVENT_MAC_STRLEN];
			char *name;
		} p2p_device_found;
		struct owfd_wpa_event_p2p_prov_disc_show_pin {
			char peer_mac[OWFD_WPA_EVENT_MAC_STRLEN];
			char *pin;
		} p2p_prov_disc_show_pin;
		struct owfd_wpa_event_p2p_prov_disc_enter_pin {
			char peer_mac[OWFD_WPA_EVENT_MAC_STRLEN];
		} p2p_prov_disc_enter_pin;
		struct owfd_wpa_event_p2p_prov_disc_pbc_req {
			char peer_mac[OWFD_WPA_EVENT_MAC_STRLEN];
		} p2p_prov_disc_pbc_req;
		struct owfd_wpa_event_p2p_prov_disc_pbc_resp {
			char peer_mac[OWFD_WPA_EVENT_MAC_STRLEN];
		} p2p_prov_disc_pbc_resp;
	} p;
};

void owfd_wpa_event_init(struct owfd_wpa_event *ev);
void owfd_wpa_event_reset(struct owfd_wpa_event *ev);
int owfd_wpa_event_parse(struct owfd_wpa_event *ev, const char *event);
const char *owfd_wpa_event_name(unsigned int type);

#ifdef __cplusplus
}
#endif

#endif /* OWFD_WPA_H */