u80211: sync with upstream and use new work system

This commit is contained in:
Matheus
2026-09-09 11:58:14 -03:00
parent 1b4e257793
commit 32efe13071
6 changed files with 266 additions and 197 deletions
+27 -6
View File
@@ -22,6 +22,7 @@ typedef struct {
bool receiving;
int current_channel;
void *work;
void *timer;
} u80211_scan_state_t;
typedef struct {
@@ -38,22 +39,34 @@ static void wake_scan_waiters(u80211_device_t *device) {
}
static void destroy_scan_state(u80211_scan_state_t *scan_state) {
u80211_kernel_free_timer(scan_state->timer);
u80211_kernel_free_work(scan_state->work);
u80211_ringbuffer_destroy(&scan_state->buffer);
u80211_kernel_free(scan_state);
}
static void cleanup_scan(void *ctx);
static void complete_scan(u80211_scan_state_t *scan_state) {
u80211_device_t *device = scan_state->device;
u80211_kernel_acquire_spinlock(device->scan_spinlock);
u80211_set_device_state(device, U80211_DEVICE_STATE_SCANNING, U80211_DEVICE_STATE_DOWN);
wake_scan_waiters(device);
device->scan_context = NULL;
u80211_kernel_release_spinlock(device->scan_spinlock);
u80211_kernel_enqueue_work(device->scan_cleanup_work, cleanup_scan, scan_state);
}
static void cleanup_scan(void *ctx) {
u80211_scan_state_t *scan_state = ctx;
u80211_device_t *device = scan_state->device;
destroy_scan_state(scan_state);
u80211_kernel_acquire_spinlock(device->scan_spinlock);
u80211_set_device_state(device, U80211_DEVICE_STATE_SCANNING, U80211_DEVICE_STATE_DOWN);
wake_scan_waiters(device);
u80211_kernel_release_spinlock(device->scan_spinlock);
}
void u80211_scan_process_response(u80211_device_t *device, u80211_beacon_data_t *beacon_data) {
@@ -151,7 +164,7 @@ static void scan_work(void *ctx) {
u80211_send_probe_request(device);
u80211_kernel_enqueue_work(scan_state->work, scan_work, scan_state, WAIT_MS);
u80211_kernel_enqueue_delayed_work(scan_state->work, scan_state->timer, scan_work, scan_state, WAIT_MS);
}
int u80211_scan(u80211_device_t *device) {
@@ -172,6 +185,14 @@ int u80211_scan(u80211_device_t *device) {
return U80211_STATUS_ENOMEM;
}
scan_state->timer = u80211_kernel_allocate_timer();
if (scan_state->timer == NULL) {
u80211_kernel_free_work(scan_state->work);
u80211_ringbuffer_destroy(&scan_state->buffer);
u80211_kernel_free(scan_state);
return U80211_STATUS_ENOMEM;
}
scan_state->receiving = false;
scan_state->device = device;
scan_state->current_channel = next_channel(0);
@@ -199,7 +220,7 @@ int u80211_scan(u80211_device_t *device) {
u80211_send_probe_request(device);
u80211_kernel_enqueue_work(scan_state->work, scan_work, scan_state, WAIT_MS);
u80211_kernel_enqueue_delayed_work(scan_state->work, scan_state->timer, scan_work, scan_state, WAIT_MS);
return U80211_STATUS_SUCCESS;
}