1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __SUPP_EVENTS_H__
8 #define __SUPP_EVENTS_H__
9 
10 #include <zephyr/net/wifi_mgmt.h>
11 
12 /* Connectivity Events */
13 #define _NET_MGMT_SUPPLICANT_LAYER NET_MGMT_LAYER_L3
14 #define _NET_MGMT_SUPPLICANT_CODE 0x157
15 #define _NET_MGMT_SUPPLICANT_BASE (NET_MGMT_LAYER(_NET_MGMT_SUPPLICANT_LAYER) | \
16 				   NET_MGMT_LAYER_CODE(_NET_MGMT_SUPPLICANT_CODE) | \
17 				   NET_MGMT_IFACE_BIT)
18 #define _NET_MGMT_SUPPLICANT_EVENT (NET_MGMT_EVENT_BIT | _NET_MGMT_SUPPLICANT_BASE)
19 
20 enum net_event_supplicant_cmd {
21 	NET_EVENT_SUPPLICANT_CMD_READY = 1,
22 	NET_EVENT_SUPPLICANT_CMD_NOT_READY,
23 	NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED,
24 	NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING,
25 	NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED,
26 	NET_EVENT_SUPPLICANT_CMD_INT_EVENT,
27 	NET_EVENT_WIFI_CMD_MAX
28 };
29 
30 #define NET_EVENT_SUPPLICANT_READY					\
31 	(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_READY)
32 
33 #define NET_EVENT_SUPPLICANT_NOT_READY					\
34 	(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_NOT_READY)
35 
36 #define NET_EVENT_SUPPLICANT_IFACE_ADDED					\
37 	(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED)
38 
39 #define NET_EVENT_SUPPLICANT_IFACE_REMOVED					\
40 	(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED)
41 
42 #define NET_EVENT_SUPPLICANT_IFACE_REMOVING					\
43 	(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING)
44 
45 #define NET_EVENT_SUPPLICANT_INT_EVENT					\
46 	(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_INT_EVENT)
47 
48 int supplicant_send_wifi_mgmt_event(const char *ifname,
49 				    enum net_event_wifi_cmd event,
50 				    void *status,
51 				    size_t len);
52 int supplicant_generate_state_event(const char *ifname,
53 				    enum net_event_supplicant_cmd event,
54 				    int status);
55 
56 #define REASON_CODE_LEN 18
57 #define NM_WIFI_EVENT_STR_LEN 64
58 #define ETH_ALEN 6
59 
60 union supplicant_event_data {
61 	struct supplicant_event_auth_reject {
62 		int auth_type;
63 		int auth_transaction;
64 		int status_code;
65 		uint8_t bssid[ETH_ALEN];
66 	} auth_reject;
67 
68 	struct supplicant_event_connected {
69 		uint8_t bssid[ETH_ALEN];
70 		char ssid[WIFI_SSID_MAX_LEN];
71 		int id;
72 	} connected;
73 
74 	struct supplicant_event_disconnected {
75 		uint8_t bssid[ETH_ALEN];
76 		int reason_code;
77 		int locally_generated;
78 	} disconnected;
79 
80 	struct supplicant_event_assoc_reject {
81 		int status_code;
82 		int reason_code;
83 	} assoc_reject;
84 
85 	struct supplicant_event_temp_disabled {
86 		int id;
87 		char ssid[WIFI_SSID_MAX_LEN];
88 		unsigned int auth_failures;
89 		unsigned int duration;
90 		char reason_code[REASON_CODE_LEN];
91 	} temp_disabled;
92 
93 	struct supplicant_event_reenabled {
94 		int id;
95 		char ssid[WIFI_SSID_MAX_LEN];
96 	} reenabled;
97 
98 	struct supplicant_event_bss_added {
99 		unsigned int id;
100 		uint8_t bssid[ETH_ALEN];
101 	} bss_added;
102 
103 	struct supplicant_event_bss_removed {
104 		unsigned int id;
105 		uint8_t bssid[ETH_ALEN];
106 	} bss_removed;
107 
108 	struct supplicant_event_network_added {
109 		unsigned int id;
110 	} network_added;
111 
112 	struct supplicant_event_network_removed {
113 		unsigned int id;
114 	} network_removed;
115 
116 	char supplicant_event_str[NM_WIFI_EVENT_STR_LEN];
117 };
118 
119 enum supplicant_event_num {
120 	SUPPLICANT_EVENT_CONNECTED,
121 	SUPPLICANT_EVENT_DISCONNECTED,
122 	SUPPLICANT_EVENT_ASSOC_REJECT,
123 	SUPPLICANT_EVENT_AUTH_REJECT,
124 	SUPPLICANT_EVENT_TERMINATING,
125 	SUPPLICANT_EVENT_SSID_TEMP_DISABLED,
126 	SUPPLICANT_EVENT_SSID_REENABLED,
127 	SUPPLICANT_EVENT_SCAN_STARTED,
128 	SUPPLICANT_EVENT_SCAN_RESULTS,
129 	SUPPLICANT_EVENT_SCAN_FAILED,
130 	SUPPLICANT_EVENT_BSS_ADDED,
131 	SUPPLICANT_EVENT_BSS_REMOVED,
132 	SUPPLICANT_EVENT_NETWORK_NOT_FOUND,
133 	SUPPLICANT_EVENT_NETWORK_ADDED,
134 	SUPPLICANT_EVENT_NETWORK_REMOVED,
135 	SUPPLICANT_EVENT_DSCP_POLICY,
136 };
137 
138 struct supplicant_int_event_data {
139 	enum supplicant_event_num event;
140 	void *data;
141 	size_t data_len;
142 };
143 
144 #endif /* __SUPP_EVENTS_H__ */
145