Просмотр исходного кода

update: airlink, 把bk wifi端实现的devinfo搬到LuatOS

??? 5 месяцев назад
Родитель
Сommit
e4e11f9339

+ 3 - 0
components/airlink/include/luat_airlink.h

@@ -211,6 +211,9 @@ int luat_airlink_drv_gpio_open(luat_gpio_cfg_t* gpio);
 
 // WLAN, 也就是wifi
 #include "luat_wlan.h"
+typedef void (*luat_airlink_wlan_evt_cb)(void *arg, luat_event_module_t event_module, int event_id, void *event_data);
+int luat_airlink_wlan_event_callback(void *arg, luat_event_module_t event_module, int event_id, void *event_data);
+
 int luat_airlink_drv_wlan_init(luat_wlan_config_t *conf);
 
 int luat_airlink_drv_wlan_mode(luat_wlan_config_t *conf);

+ 1 - 2
components/airlink/src/devinfo/luat_airlink_devinfo_mobile.c

@@ -155,8 +155,7 @@ static int mobile_evt_handler(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t
     return 0;
 }
 
-void luat_airlink_devinfo_init(AIRLINK_DEV_INFO_UPDATE_CB cb) 
-{
+void luat_airlink_devinfo_init(AIRLINK_DEV_INFO_UPDATE_CB cb) {
     send_devinfo_update_evt = cb;
     g_airlink_self_dev_info.tp = 0x02;
     uint32_t fw_version = 3;

+ 135 - 5
components/airlink/src/devinfo/luat_airlink_devinfo_wlan.c

@@ -1,21 +1,151 @@
 #include "luat_base.h"
 #include "luat_airlink.h"
 
-#if defined(LUAT_USE_AIRLINK_EXEC_WLAN )
+#if defined(LUAT_USE_AIRLINK_EXEC_WLAN)
 #include "luat_wlan.h"
 #endif
 
-// TODO 把wifi侧的实现, 也搬过来
+#define LUAT_LOG_TAG "airlink"
+#include "luat_log.h"
 
 extern luat_airlink_dev_info_t g_airlink_self_dev_info;
+extern luat_airlink_wlan_evt_cb g_airlink_wlan_evt_cb;
+extern int luat_airlink_drv_wlan_scan_result_cb(void);
 
 static AIRLINK_DEV_INFO_UPDATE_CB send_devinfo_update_evt = NULL;
 
 #if defined(LUAT_USE_AIRLINK_EXEC_WLAN)
-#if 0
+int wifi_evt_handler(void *arg, luat_event_module_t event_module, int event_id, void *event_data) {
+    luat_wifi_event_sta_disconnected_t *sta_disconnected;
+	luat_wifi_event_sta_connected_t *sta_connected;
+	luat_wifi_event_ap_disconnected_t *ap_disconnected;
+	luat_wifi_event_ap_connected_t *ap_connected;
+	luat_wifi_event_network_found_t *network_found;
+
+    // luat_airlink_dev_info_t *devinfo = self_devinfo();
+    uint8_t buff[256] = {0};
+    int ret = 0;
+    int remain = 256;
+    uint8_t *ptr = buff;
+    switch (event_id)
+    {
+    case LUAT_WLAN_EVENT_WIFI_SCAN_DONE:
+        LLOGD("scan done");
+        luat_airlink_drv_wlan_scan_result_cb();
+        send_devinfo_update_evt();
+        break;
+    case LUAT_WLAN_EVENT_WIFI_STA_CONNECTED:
+        // // 通知主机
+        g_airlink_self_dev_info.wifi.sta_state = 1;
+        sta_connected = (luat_wifi_event_sta_connected_t *)event_data;
+        LLOGD("STA connected %s", sta_connected->ssid);
+
+        ret = luat_airlink_syspub_addstring("WLAN_STA_INC", strlen("WLAN_STA_INC"), ptr, remain);
+        ptr += ret;
+        remain -= ret;
+
+        ret = luat_airlink_syspub_addstring("CONNECTED", strlen("CONNECTED"), ptr, remain);
+        ptr += ret;
+        remain -= ret;
+
+        ret = luat_airlink_syspub_addstring(sta_connected->ssid, strlen(sta_connected->ssid), ptr, remain);
+        ptr += ret;
+        remain -= ret;
+
+        ret = luat_airlink_syspub_addstring((const char*)sta_connected->bssid, 6, ptr, remain);
+        ptr += ret;
+        remain -= ret;
+
+        luat_airlink_syspub_send(buff, ptr - buff);
+        send_devinfo_update_evt();
+        break;
+
+    case LUAT_WLAN_EVENT_WIFI_STA_DISCONNECTED:
+        g_airlink_self_dev_info.wifi.sta_state = 0;
+        sta_disconnected = (luat_wifi_event_sta_disconnected_t *)event_data;
+        if (sta_disconnected->disconnect_reason > 0) {
+            LLOGD("STA disconnected, reason(%d) is_local %d", sta_disconnected->disconnect_reason, sta_disconnected->local_generated); 
+            
+            ret = luat_airlink_syspub_addstring("WLAN_STA_INC", strlen("WLAN_STA_INC"), ptr, remain);
+            ptr += ret;
+            remain -= ret;
+
+            ret = luat_airlink_syspub_addstring("DISCONNECTED", strlen("DISCONNECTED"), ptr, remain);
+            ptr += ret;
+            remain -= ret;
+
+            ret = luat_airlink_syspub_addint32(sta_disconnected->disconnect_reason, ptr, remain);
+            ptr += ret;
+            remain -= ret;
+
+            luat_airlink_syspub_send(buff, ptr - buff);
+            send_devinfo_update_evt();
+        }
+        else {
+            send_devinfo_update_evt();
+            return 0; // reason == 0 的时候不需要发消息
+        }
+        break;
+    case LUAT_WLAN_EVENT_WIFI_AP_CONNECTED:
+        ap_connected = (luat_wifi_event_ap_connected_t *)event_data;
+        // LLOGD(BK_MAC_FORMAT" connected to AP", BK_MAC_STR(ap_connected->mac));
+
+        ret = luat_airlink_syspub_addstring("WLAN_AP_INC", strlen("WLAN_AP_INC"), ptr, remain);
+        ptr += ret;
+        remain -= ret;
+        
+        ret = luat_airlink_syspub_addstring("CONNECTED", strlen("CONNECTED"), ptr, remain);
+        ptr += ret;
+        remain -= ret;
+
+        ret = luat_airlink_syspub_addstring((const char*)ap_connected->mac, 6, ptr, remain);
+        ptr += ret;
+        remain -= ret;
+        
+        luat_airlink_syspub_send(buff, ptr - buff);
+        send_devinfo_update_evt();
+        break;
+    case LUAT_WLAN_EVENT_WIFI_AP_DISCONNECTED:
+        ap_disconnected = (luat_wifi_event_ap_disconnected_t *)event_data;
+        // LLOGD(BK_MAC_FORMAT" disconnected from AP", BK_MAC_STR(ap_disconnected->mac));
+        
+        ret = luat_airlink_syspub_addstring("WLAN_AP_INC", strlen("WLAN_AP_INC"), ptr, remain);
+        ptr += ret;
+        remain -= ret;
+        
+        ret = luat_airlink_syspub_addstring("DISCONNECTED", strlen("DISCONNECTED"), ptr, remain);
+        ptr += ret;
+        remain -= ret;
+
+        ret = luat_airlink_syspub_addstring((const char*)ap_disconnected->mac, 6, ptr, remain);
+        ptr += ret;
+        remain -= ret;
+
+        luat_airlink_syspub_send(buff, ptr - buff);
+        send_devinfo_update_evt();
+        break;
+    case LUAT_WLAN_EVENT_WIFI_NETWORK_FOUND:
+        network_found = (luat_wifi_event_network_found_t *)event_data;
+        LLOGD(" target AP: %s, bssid %p found", network_found->ssid, network_found->bssid);
+        send_devinfo_update_evt();
+        break;
+    }
+    return 0;
+}
+
+void luat_bk72xx_update_ap(uint8_t state) {
+    LLOGI("AP状态变化 %d", state);
+    g_airlink_self_dev_info.wifi.ap_state = state;
+    send_devinfo_update_evt();
+}
+
 void luat_airlink_devinfo_init(AIRLINK_DEV_INFO_UPDATE_CB cb) 
 {
-    
+    send_devinfo_update_evt = cb;
+    g_airlink_self_dev_info.tp = 0x01;
+    uint32_t fw_version = 15;
+    memcpy(g_airlink_self_dev_info.wifi.version, &fw_version, sizeof(uint32_t));   // 版本
+    g_airlink_wlan_evt_cb = wifi_evt_handler;
+    send_devinfo_update_evt();
 }
 #endif
-#endif

+ 17 - 1
components/airlink/src/driver/luat_airlink_drv_wlan.c

@@ -18,6 +18,9 @@
 #undef LLOGD
 #define LLOGD(...) 
 
+luat_airlink_wlan_evt_cb g_airlink_wlan_evt_cb;
+extern luat_airlink_dev_info_t g_airlink_ext_dev_info;
+
 int luat_airlink_drv_wlan_init(luat_wlan_config_t* args) {
     uint64_t luat_airlink_next_cmd_id = luat_airlink_get_next_cmd_id();
     airlink_queue_item_t item = {
@@ -218,4 +221,17 @@ int luat_airlink_drv_wlan_scan_result_cb(void) {
     luat_airlink_queue_send(LUAT_AIRLINK_QUEUE_CMD, &item);
 
     return 0;
-}
+}
+
+extern void luat_airlink_devinfo_init(AIRLINK_DEV_INFO_UPDATE_CB cb);
+int luat_airlink_drv_devinfo_init(AIRLINK_DEV_INFO_UPDATE_CB cb) {
+    luat_airlink_devinfo_init(cb);
+    return 0;
+}
+
+int luat_airlink_wlan_event_callback(void *arg, luat_event_module_t event_module, int event_id, void *event_data) {
+	if (g_airlink_wlan_evt_cb) {
+		g_airlink_wlan_evt_cb(arg, event_module, event_id, event_data);
+	}
+    return 0;
+}

+ 73 - 0
components/wlan/luat_wlan.h

@@ -49,6 +49,79 @@ enum LUAT_WLAN_ENCRYPT_MODE {
     LUAT_WLAN_ENCRYPT_WPA2
 };
 
+typedef enum LUAT_EVENT_MODULE {
+	LUAT_WLAN_EVENT_MOD_WIFI_INTERNAL,   /**< WiFi internal event */
+	LUAT_WLAN_EVENT_MOD_WIFI,            /**< WiFi public event */
+	LUAT_WLAN_EVENT_MOD_NETIF,           /**< Netif event */
+	LUAT_WLAN_EVENT_MOD_COUNT,           /**< Event module count */
+} luat_event_module_t;
+
+/**
+ * @brief WiFi public event type
+ */
+typedef enum LUAT_WIFI_EVENT {
+	LUAT_WLAN_EVENT_WIFI_SCAN_DONE = 0,      /**< WiFi scan done event */
+	LUAT_WLAN_EVENT_WIFI_CSI_DATA_IND,
+	LUAT_WLAN_EVENT_WIFI_CSI_ALG_IND,
+
+	LUAT_WLAN_EVENT_WIFI_STA_CONNECTED,      /**< The BK STA is connected */
+	LUAT_WLAN_EVENT_WIFI_STA_DISCONNECTED,   /**< The BK STA is disconnected */
+
+	LUAT_WLAN_EVENT_WIFI_AP_CONNECTED,       /**< A STA is connected to the BK AP */
+	LUAT_WLAN_EVENT_WIFI_AP_DISCONNECTED,    /**< A STA is disconnected from the BK AP */
+
+	LUAT_WLAN_EVENT_WIFI_NETWORK_FOUND,      /**< The BK STA find target AP */
+	LUAT_WLAN_EVENT_WIFI_COUNT,              /**< WiFi event count */
+} luat_wifi_event_t;
+
+typedef enum LUAT_WIFI_COUNTRY_POLICY {
+	LUAT_WLAN_WIFI_COUNTRY_POLICY_AUTO,   /**< Country policy is auto, use the country info of AP to which the station is connected */
+	LUAT_WLAN_WIFI_COUNTRY_POLICY_MANUAL, /**< Country policy is manual, always use the configured country info */
+} luat_wifi_country_policy_t;     
+
+typedef struct luat_wifi_country
+{
+	char                  cc[3];          /**< country code string */
+	uint8_t               schan;          /**< start channel */
+	uint8_t               nchan;          /**< total channel number */
+	int8_t                max_tx_power;   /**< maximum tx power */
+	luat_wifi_country_policy_t policy;         /**< country policy */
+} luat_wifi_country_t;
+
+typedef struct luat_wifi_event_scan_done
+{
+	uint32_t scan_id; /**< Scan ID */
+	uint32_t scan_use_time;/**< scan time. us */
+} luat_wifi_event_scan_done_t;
+
+typedef struct luat_wifi_event_network_found
+{
+	char    ssid[33];      /**< SSID found to be connected */
+	uint8_t bssid[6];        /**< BSSID found to be connected */
+} luat_wifi_event_network_found_t;
+
+typedef struct luat_wifi_event_sta_connected
+{
+	char    ssid[33];      /**< SSID of connected AP */
+	uint8_t bssid[6];        /**< BSSID of connected AP*/
+} luat_wifi_event_sta_connected_t;
+
+typedef struct luat_wifi_event_sta_disconnected
+{
+	int disconnect_reason;                /**< Disconnect reason of BK STA */
+	uint8_t local_generated;                 /**< if disconnect is request by local */
+} luat_wifi_event_sta_disconnected_t;
+
+typedef struct luat_wifi_event_ap_connected
+{
+	uint8_t mac[6];            /**< MAC of the STA connected to the BK AP */
+} luat_wifi_event_ap_connected_t;
+
+typedef struct luat_wifi_event_ap_disconnected
+{
+	uint8_t mac[6];            /**< MAC of the STA disconnected from the BK AP */
+} luat_wifi_event_ap_disconnected_t;
+
 typedef struct luat_wlan_scan_result
 {
     char ssid[33];