@@ -44,24 +44,57 @@ int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) {
44
44
45
45
int arduino::WiFiClass::beginAP (const char * ssid, const char *passphrase, uint8_t channel) {
46
46
47
- #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
48
- _softAP = WhdSoftAPInterface::get_default_instance ();
49
- #endif
47
+ #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
48
+ _softAP = WhdSoftAPInterface::get_default_instance ();
49
+ #endif
50
50
51
51
if (_softAP == NULL ) {
52
- return WL_AP_FAILED;
52
+ return (_currentNetworkStatus = WL_AP_FAILED) ;
53
53
}
54
54
55
55
ensureDefaultAPNetworkConfiguration ();
56
56
57
+ WhdSoftAPInterface* softAPInterface = static_cast <WhdSoftAPInterface*>(_softAP);
58
+
57
59
// Set ap ssid, password and channel
58
- static_cast <WhdSoftAPInterface*>(_softAP) ->set_network (_ip, _netmask, _gateway);
59
- nsapi_error_t result = static_cast <WhdSoftAPInterface*>(_softAP) ->start (ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */ , NULL , true /* cohexistance */ );
60
+ softAPInterface ->set_network (_ip, _netmask, _gateway);
61
+ nsapi_error_t result = softAPInterface ->start (ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */ , NULL , true /* cohexistance */ );
60
62
63
+ nsapi_error_t registrationResult;
64
+ softAPInterface->unregister_event_handler ();
65
+ registrationResult = softAPInterface->register_event_handler (arduino::WiFiClass::handleAPEvents);
66
+
67
+ if (registrationResult != NSAPI_ERROR_OK) {
68
+ return (_currentNetworkStatus = WL_AP_FAILED);
69
+ }
70
+
61
71
_currentNetworkStatus = (result == NSAPI_ERROR_OK && setSSID (ssid)) ? WL_AP_LISTENING : WL_AP_FAILED;
62
72
return _currentNetworkStatus;
63
73
}
64
74
75
+ void * arduino::WiFiClass::handleAPEvents (whd_interface_t ifp, const whd_event_header_t *event_header, const uint8_t *event_data, void *handler_user_data){
76
+ if (event_header->event_type == WLC_E_ASSOC_IND){
77
+ WiFi._currentNetworkStatus = WL_AP_CONNECTED;
78
+ } else if (event_header->event_type == WLC_E_DISASSOC_IND){
79
+ WiFi._currentNetworkStatus = WL_AP_LISTENING;
80
+ }
81
+
82
+ // Default Event Handler
83
+ whd_driver_t whd_driver = ifp->whd_driver ;
84
+ WHD_IOCTL_LOG_ADD_EVENT (whd_driver, event_header->event_type , event_header->flags , event_header->reason );
85
+
86
+ if ((event_header->event_type == (whd_event_num_t )WLC_E_LINK) || (event_header->event_type == WLC_E_IF)) {
87
+ if (osSemaphoreGetCount (whd_driver->ap_info .whd_wifi_sleep_flag ) < 1 ) {
88
+ osStatus_t result = osSemaphoreRelease (whd_driver->ap_info .whd_wifi_sleep_flag );
89
+ if (result != osOK) {
90
+ printf (" Release whd_wifi_sleep_flag ERROR: %d" , result);
91
+ }
92
+ }
93
+ }
94
+
95
+ return handler_user_data;
96
+ }
97
+
65
98
void arduino::WiFiClass::ensureDefaultAPNetworkConfiguration () {
66
99
if (_ip == nullptr ){
67
100
_ip = SocketAddress (DEFAULT_IP_ADDRESS);
@@ -80,10 +113,15 @@ void arduino::WiFiClass::end() {
80
113
81
114
int arduino::WiFiClass::disconnect () {
82
115
if (_softAP != nullptr ) {
83
- return static_cast <WhdSoftAPInterface*>(_softAP)->stop ();
116
+ WhdSoftAPInterface* softAPInterface = static_cast <WhdSoftAPInterface*>(_softAP);
117
+ softAPInterface->unregister_event_handler ();
118
+ _currentNetworkStatus = (softAPInterface->stop () == NSAPI_ERROR_OK ? WL_DISCONNECTED : WL_AP_FAILED);
84
119
} else {
85
- return wifi_if->disconnect ();
120
+ wifi_if->disconnect ();
121
+ _currentNetworkStatus = WL_DISCONNECTED;
86
122
}
123
+
124
+ return _currentNetworkStatus;
87
125
}
88
126
89
127
void arduino::WiFiClass::config (arduino::IPAddress local_ip){
0 commit comments