Skip to content

Commit 8503aab

Browse files
committed
Add a callback for association of station in AP mode
The callback is available when CYW43_ASSOC_CALLBACK is defined to 1 and can be used to report when stations are associated or disassociated. Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent faf3638 commit 8503aab

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/cyw43.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ typedef struct _cyw43_t {
149149
#if CYW43_ENABLE_BLUETOOTH
150150
bool bt_loaded;
151151
#endif
152+
#if CYW43_ASSOC_CALLBACK
153+
void (*assoc_cb)(bool assoc);
154+
#endif
152155
} cyw43_t;
153156

154157
extern cyw43_t cyw43_state;

src/cyw43_ctrl.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ void cyw43_init(cyw43_t *self) {
109109
#if CYW43_ENABLE_BLUETOOTH
110110
self->bt_loaded = false;
111111
#endif
112+
#if CYW43_ASSOC_CALLBACK
113+
self->assoc_cb = NULL;
114+
#endif
112115
}
113116

114117
void cyw43_deinit(cyw43_t *self) {
@@ -342,11 +345,23 @@ void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev)
342345
cyw43_cb_tcpip_set_link_down(self, CYW43_ITF_STA);
343346
self->wifi_join_state = 0x0000;
344347

345-
#if 0
348+
// WiFi ap events
349+
#if CYW43_ASSOC_CALLBACK
350+
} else if (ev->event_type == CYW43_EV_ASSOC_IND) {
351+
if (ev->interface == CYW43_ITF_AP) {
352+
if (self->assoc_cb) {
353+
self->assoc_cb(true);
354+
}
355+
}
346356
} else if (ev->event_type == CYW43_EV_DISASSOC_IND) {
347357
if (ev->interface == CYW43_ITF_AP) {
358+
#if 0
348359
// Station disassociated with our AP, let DHCP server know so it can free the IP address
349360
dhcp_server_disassoc(&self->dhcp_server, buf + 24);
361+
#endif
362+
if (self->assoc_cb) {
363+
self->assoc_cb(false);
364+
}
350365
}
351366
#endif
352367

@@ -382,10 +397,18 @@ void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev)
382397
self->wifi_join_state = WIFI_JOIN_STATE_BADAUTH;
383398
}
384399
} else if (ev->event_type == CYW43_EV_DEAUTH_IND) {
385-
if (ev->status == 0 && ev->reason == 2) {
386-
// Deauth, probably because password was wrong; disassociate
387-
self->pend_disassoc = true;
388-
cyw43_schedule_internal_poll_dispatch(cyw43_poll_func);
400+
if (ev->interface == CYW43_ITF_STA) {
401+
if (ev->status == 0 && ev->reason == 2) {
402+
// Deauth, probably because password was wrong; disassociate
403+
self->pend_disassoc = true;
404+
cyw43_schedule_internal_poll_dispatch(cyw43_poll_func);
405+
}
406+
#if CYW43_ASSOC_CALLBACK
407+
} else {
408+
if (self->assoc_cb) {
409+
self->assoc_cb(false);
410+
}
411+
#endif
389412
}
390413
} else if (ev->event_type == CYW43_EV_LINK) {
391414
if (ev->status == 0) {

src/cyw43_ll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#define CYW43_EV_DEAUTH (5)
7171
#define CYW43_EV_DEAUTH_IND (6)
7272
#define CYW43_EV_ASSOC (7)
73+
#define CYW43_EV_ASSOC_IND (8)
7374
#define CYW43_EV_DISASSOC (11)
7475
#define CYW43_EV_DISASSOC_IND (12)
7576
#define CYW43_EV_LINK (16)

0 commit comments

Comments
 (0)