Skip to content

Commit 027c9c0

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 8ef38a6 commit 027c9c0

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
@@ -117,6 +117,9 @@ void cyw43_init(cyw43_t *self) {
117117
#if CYW43_ENABLE_BLUETOOTH
118118
self->bt_loaded = false;
119119
#endif
120+
#if CYW43_ASSOC_CALLBACK
121+
self->assoc_cb = NULL;
122+
#endif
120123
}
121124

122125
void cyw43_deinit(cyw43_t *self) {
@@ -350,11 +353,23 @@ void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev)
350353
cyw43_cb_tcpip_set_link_down(self, CYW43_ITF_STA);
351354
self->wifi_join_state = 0x0000;
352355

353-
#if 0
356+
// WiFi ap events
357+
#if CYW43_ASSOC_CALLBACK
358+
} else if (ev->event_type == CYW43_EV_ASSOC_IND) {
359+
if (ev->interface == CYW43_ITF_AP) {
360+
if (self->assoc_cb) {
361+
self->assoc_cb(true);
362+
}
363+
}
354364
} else if (ev->event_type == CYW43_EV_DISASSOC_IND) {
355365
if (ev->interface == CYW43_ITF_AP) {
366+
#if 0
356367
// Station disassociated with our AP, let DHCP server know so it can free the IP address
357368
dhcp_server_disassoc(&self->dhcp_server, buf + 24);
369+
#endif
370+
if (self->assoc_cb) {
371+
self->assoc_cb(false);
372+
}
358373
}
359374
#endif
360375

@@ -390,10 +405,18 @@ void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev)
390405
self->wifi_join_state = WIFI_JOIN_STATE_BADAUTH;
391406
}
392407
} else if (ev->event_type == CYW43_EV_DEAUTH_IND) {
393-
if (ev->status == 0 && ev->reason == 2) {
394-
// Deauth, probably because password was wrong; disassociate
395-
self->pend_disassoc = true;
396-
cyw43_schedule_internal_poll_dispatch(cyw43_poll_func);
408+
if (ev->interface == CYW43_ITF_STA) {
409+
if (ev->status == 0 && ev->reason == 2) {
410+
// Deauth, probably because password was wrong; disassociate
411+
self->pend_disassoc = true;
412+
cyw43_schedule_internal_poll_dispatch(cyw43_poll_func);
413+
}
414+
#if CYW43_ASSOC_CALLBACK
415+
} else {
416+
if (self->assoc_cb) {
417+
self->assoc_cb(false);
418+
}
419+
#endif
397420
}
398421
} else if (ev->event_type == CYW43_EV_LINK) {
399422
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)