Skip to content

Commit 5d0ce3c

Browse files
authored
Merge pull request #4338 from andreaslarssonublox/ublox_odin_driver_os_5_v1.3_rc2
u-blox ODIN driver v1.3 rc2 for mbed OS 5
2 parents a2a1581 + e563fd4 commit 5d0ce3c

File tree

16 files changed

+470
-115
lines changed

16 files changed

+470
-115
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/sdk/ublox-odin-w2-drivers/OdinWiFiInterface.h

Lines changed: 167 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@
1818
#define ODIN_WIFI_INTERFACE_H
1919

2020
#include "WiFiInterface.h"
21-
#include "Callback.h"
22-
#include "mbed_events.h"
23-
24-
#include "rtos.h"
25-
#include "cmsis_os.h"
2621
#include "emac_api.h"
22+
23+
#include "mbed.h"
24+
#include "netsocket/WiFiAccessPoint.h"
2725
#include "nsapi_types.h"
2826
#include "lwip/netif.h"
27+
#include "rtos.h"
28+
#include "cb_wlan.h"
2929

30-
typedef Queue<void*, 1> MsgQueue;
31-
32-
class OdinWiFiInterface;
30+
#define ODIN_WIFI_MAX_MAC_ADDR_STR (18)
31+
#define ODIN_WIFI_SCAN_CACHE_SIZE (5)
3332

34-
struct PrivContext;
33+
struct odin_wifi_msg_s;
34+
struct user_connect_s;
35+
struct user_scan_s;
36+
struct user_ap_start_s;
37+
struct wlan_status_started_s;
38+
struct wlan_status_connected_s;
39+
struct wlan_status_connection_failure_s;
40+
struct wlan_scan_indication_s;
3541

3642
/** OdinWiFiInterface class
3743
* Implementation of the WiFiInterface for the ODIN-W2 module
@@ -74,7 +80,8 @@ class OdinWiFiInterface : public WiFiInterface
7480
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
7581
* @return 0 on success, or error code on failure
7682
*/
77-
virtual nsapi_error_t connect(const char *ssid,
83+
virtual nsapi_error_t connect(
84+
const char *ssid,
7885
const char *pass,
7986
nsapi_security_t security = NSAPI_SECURITY_NONE,
8087
uint8_t channel = 0);
@@ -115,7 +122,7 @@ class OdinWiFiInterface : public WiFiInterface
115122
/** Get the local network mask
116123
*
117124
* @return Null-terminated representation of the local network mask
118-
* or null if no network mask has been recieved
125+
* or null if no network mask has been received
119126
*/
120127
virtual const char *get_netmask();
121128

@@ -177,44 +184,161 @@ class OdinWiFiInterface : public WiFiInterface
177184
* specified since the Wi-Fi driver might need some time to finish and cleanup.
178185
* @return 0 on success, negative error code on failure
179186
*/
180-
virtual void set_timeout(int timeout);
187+
virtual nsapi_error_t set_timeout(int ms);
181188

182189
virtual NetworkStack *get_stack();
183190

184191
protected:
185192

186193
private:
187-
188-
nsapi_error_t connect_async(const char *ssid,
189-
const char *pass,
190-
nsapi_security_t security = NSAPI_SECURITY_NONE,
191-
uint8_t channel = 0,
192-
void *data = NULL,
193-
unsigned timeout = 0);
194-
195-
bool start(bool debug);
196-
bool stop();
197-
198-
char _mac_addr_str[18];
199-
// Private context to share between C and C++ calls
200-
PrivContext* _priv_context;
201-
const char *_ssid;
202-
const char *_pass;
203-
char _ip_address[IPADDR_STRLEN_MAX];
204-
char _netmask[IPADDR_STRLEN_MAX];
205-
char _gateway[IPADDR_STRLEN_MAX];
206-
nsapi_security_t _security;
207-
uint8_t _channel;
208-
bool _use_dhcp;
209-
int _timeout;
210-
// Event queue when the driver context need to be used
211-
EventQueue* _odin_event_queue;
212-
int32_t target_id;
213-
// Event queue for sending start up and connection events from driver to this class
214-
MsgQueue _event_queue;
215-
// Message queue for sending scan events from driver to this class
216-
osMessageQId _scan_msg_queue_id;
217-
osMessageQDef_t _queue_def;
194+
195+
enum OdinWifiState {
196+
S_NOT_INITIALISED = 1,
197+
S_WAIT_START,
198+
S_STARTED,
199+
S_WAIT_STOP,
200+
201+
S_STA_IDLE,
202+
S_STA_WAIT_CONNECT,
203+
S_STA_CONNECTED,
204+
S_STA_DISCONNECTED_WAIT_CONNECT,
205+
S_STA_CONNECTION_FAIL_WAIT_DISCONNECT,
206+
//S_STA_LINK_LOSS_WAIT_DISCONNECT,
207+
S_STA_WAIT_DISCONNECT,
208+
209+
S_AP_IDLE,
210+
S_AP_WAIT_START,
211+
S_AP_STARTED,
212+
S_AP_WAIT_STOP,
213+
S_AP_FAIL_WAIT_STOP,
214+
S_AP_WAIT_DRV_STOP,
215+
S_AP_WAIT_DRV_START,
216+
217+
S_INVALID
218+
};
219+
220+
struct sta_s {
221+
const char *ssid;
222+
const char *passwd;
223+
nsapi_security_t security;
224+
uint8_t channel;
225+
bool use_dhcp;
226+
int timeout_ms;
227+
char ip_address[IPADDR_STRLEN_MAX];
228+
char netmask[IPADDR_STRLEN_MAX];
229+
char gateway[IPADDR_STRLEN_MAX];
230+
};
231+
232+
struct ap_s {
233+
const char *ssid;
234+
const char *passwd;
235+
nsapi_security_t security;
236+
uint8_t channel;
237+
bool use_dhcp;
238+
239+
char ip_address[IPADDR_STRLEN_MAX];
240+
char netmask[IPADDR_STRLEN_MAX];
241+
char gateway[IPADDR_STRLEN_MAX];
242+
243+
int cnt_connected;
244+
245+
nsapi_error_t error_code;
246+
};
247+
248+
struct scan_cache_s {
249+
int count;
250+
uint8_t last_channel;
251+
cbWLAN_MACAddress bssid[ODIN_WIFI_SCAN_CACHE_SIZE];
252+
};
253+
254+
OdinWifiState entry_connect_fail_wait_disconnect();
255+
OdinWifiState entry_wait_connect();
256+
OdinWifiState entry_wait_disconnect();
257+
//OdinWifiState entry_link_loss_wait_disconnect(void);
258+
OdinWifiState entry_ap_wait_start();
259+
OdinWifiState entry_ap_started();
260+
OdinWifiState entry_ap_wait_stop();
261+
OdinWifiState entry_ap_fail_wait_stop();
262+
OdinWifiState entry_ap_wait_drv_stop();
263+
OdinWifiState entry_ap_wait_drv_start();
264+
265+
void handle_in_msg();
266+
void handle_cached_msg();
267+
268+
void handle_user_connect(user_connect_s *user_connect);
269+
void handle_user_disconnect();
270+
void handle_user_scan(user_scan_s *user_scan);
271+
void handle_user_connect_timeout();
272+
void handle_user_stop();
273+
274+
void handle_user_ap_start(user_ap_start_s *user_ap_start);
275+
void handle_user_ap_stop();
276+
277+
void handle_wlan_status_started(wlan_status_started_s *start);
278+
void handle_wlan_status_stopped(void);
279+
void handle_wlan_status_error(void);
280+
void handle_wlan_status_connecting(void);
281+
void handle_wlan_status_connected(wlan_status_connected_s *wlan_connect);
282+
void handle_wlan_status_connection_failure(wlan_status_connection_failure_s *connect_failure);
283+
void handle_wlan_status_disconnected(void);
284+
void handle_wlan_scan_indication();
285+
286+
void handle_wlan_status_ap_up();
287+
void handle_wlan_status_ap_down();
288+
289+
void init(bool debug);
290+
nsapi_error_t wlan_set_channel(uint8_t channel);
291+
nsapi_error_t wlan_connect(
292+
const char *ssid,
293+
const char *passwd,
294+
nsapi_security_t security);
295+
nsapi_error_t wlan_ap_start(
296+
const char *ssid,
297+
const char *pass,
298+
nsapi_security_t security,
299+
uint8_t channel);
300+
301+
void timeout_user_connect();
302+
void update_scan_list(cbWLAN_ScanIndicationInfo *scan_info);
303+
void send_user_response_msg(unsigned int type, nsapi_error_t error_code);
304+
void wlan_status_indication(cbWLAN_StatusIndicationInfo status, void *data);
305+
void wlan_scan_indication(cbWLAN_ScanIndicationInfo *scan_info, cb_boolean is_last_result);
306+
307+
static bool _wlan_initialized; // Controls that cbWLAN is initiated only once
308+
static emac_interface_t* _emac; // Not possible to remove added interfaces to the network stack => static and re-use
309+
static int32_t _target_id;
310+
311+
OdinWifiState _state;
312+
OdinWifiState _state_sta;
313+
OdinWifiState _state_ap;
314+
315+
struct sta_s _sta;
316+
struct ap_s _ap;
317+
nsapi_stack_t _stack;
318+
char _mac_addr_str[ODIN_WIFI_MAX_MAC_ADDR_STR];
319+
320+
cbWLAN_StatusConnectedInfo _wlan_status_connected_info;
321+
cbWLAN_StatusDisconnectedInfo _wlan_status_disconnected_info;
322+
323+
bool _scan_active;
324+
WiFiAccessPoint *_scan_list;
325+
nsapi_size_t _scan_list_size;
326+
nsapi_size_t _scan_list_cnt;
327+
struct scan_cache_s _scan_cache;
328+
329+
friend struct wlan_callb_s;
330+
331+
Mutex _mutex;
332+
Queue<odin_wifi_msg_s, 6> _in_queue;
333+
Queue<odin_wifi_msg_s, 1> _out_queue;
334+
Queue<odin_wifi_msg_s, 1> _cache_queue;
335+
MemoryPool<odin_wifi_msg_s, 7> *_msg_pool;
336+
Thread _thread;
337+
//Timeout _timeout; //Randomly lost interrupts/callbacks; replaced by Timer
338+
Timer _timer;
339+
340+
bool _debug;
341+
int _dbg_timeout;
218342
};
219343

220344
#endif

targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/sdk/ublox-odin-w2-drivers/bt_types.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*---------------------------------------------------------------------------
2-
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
2+
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
33
* SPDX-License-Identifier: LicenseRef-PBL
44
*
55
* This file and the related binary are licensed under the
@@ -65,6 +65,11 @@
6565

6666
#define PACKET_TYPE_ALL (PACKET_TYPE_DM1 | PACKET_TYPE_DH1 | PACKET_TYPE_DM3 | PACKET_TYPE_DH3 | PACKET_TYPE_DM5 | PACKET_TYPE_DH5)
6767

68+
#define BD_ADDR_IS_STATIC_RANDOM(BdAddress) ((BdAddress[0] & 0xC0) == 0xC0)
69+
#define BD_ADDR_IS_NON_RESOLVABLE(BdAddress) ((BdAddress[0] & 0xC0) == 0x00)
70+
#define BD_ADDR_IS_RESOLVABLE(BdAddress) ((BdAddress[0] & 0xC0) == 0x40)
71+
72+
#define BT_INVALID_STATIC_LINK_KEY (0)
6873
/*===========================================================================
6974
* TYPES
7075
*=========================================================================*/

0 commit comments

Comments
 (0)