From a516dbd5e27e73d4e2c245d8903c57d97186cbaa Mon Sep 17 00:00:00 2001
From: Gustav Toft <guto@factbird.com>
Date: Wed, 5 Jun 2024 08:14:35 +0200
Subject: [PATCH] CYW43: Add function to close existing soft AP

---
 cyw43/src/control.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs
index cd890c982..0a8cb9c8c 100644
--- a/cyw43/src/control.rs
+++ b/cyw43/src/control.rs
@@ -393,6 +393,23 @@ impl<'a> Control<'a> {
         self.set_iovar_u32x2("bss", 0, 1).await; // bss = BSS_UP
     }
 
+    pub async fn close_ap(&mut self) {
+        // Stop AP
+        self.set_iovar_u32x2("bss", 0, 0).await; // bss = BSS_DOWN
+
+        // Turn off AP mode
+        self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 0).await;
+
+        // Temporarily set wifi down
+        self.down().await;
+
+        // Turn on APSTA mode
+        self.set_iovar_u32("apsta", 1).await;
+
+        // Set wifi up again
+        self.up().await;
+    }
+
     /// Add specified address to the list of hardware addresses the device
     /// listens on. The address must be a Group address (I/G bit set). Up
     /// to 10 addresses are supported by the firmware. Returns the number of