Skip to content

Commit

Permalink
Merge pull request #4338 from andreaslarssonublox/ublox_odin_driver_o…
Browse files Browse the repository at this point in the history
…s_5_v1.3_rc2

u-blox ODIN driver v1.3 rc2 for mbed OS 5
  • Loading branch information
0xc0170 committed May 19, 2017
2 parents a2a1581 + e563fd4 commit 5d0ce3c
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 115 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@
#define ODIN_WIFI_INTERFACE_H

#include "WiFiInterface.h"
#include "Callback.h"
#include "mbed_events.h"

#include "rtos.h"
#include "cmsis_os.h"
#include "emac_api.h"

#include "mbed.h"
#include "netsocket/WiFiAccessPoint.h"
#include "nsapi_types.h"
#include "lwip/netif.h"
#include "rtos.h"
#include "cb_wlan.h"

typedef Queue<void*, 1> MsgQueue;

class OdinWiFiInterface;
#define ODIN_WIFI_MAX_MAC_ADDR_STR (18)
#define ODIN_WIFI_SCAN_CACHE_SIZE (5)

struct PrivContext;
struct odin_wifi_msg_s;
struct user_connect_s;
struct user_scan_s;
struct user_ap_start_s;
struct wlan_status_started_s;
struct wlan_status_connected_s;
struct wlan_status_connection_failure_s;
struct wlan_scan_indication_s;

/** OdinWiFiInterface class
* Implementation of the WiFiInterface for the ODIN-W2 module
Expand Down Expand Up @@ -74,7 +80,8 @@ class OdinWiFiInterface : public WiFiInterface
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
* @return 0 on success, or error code on failure
*/
virtual nsapi_error_t connect(const char *ssid,
virtual nsapi_error_t connect(
const char *ssid,
const char *pass,
nsapi_security_t security = NSAPI_SECURITY_NONE,
uint8_t channel = 0);
Expand Down Expand Up @@ -115,7 +122,7 @@ class OdinWiFiInterface : public WiFiInterface
/** Get the local network mask
*
* @return Null-terminated representation of the local network mask
* or null if no network mask has been recieved
* or null if no network mask has been received
*/
virtual const char *get_netmask();

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

virtual NetworkStack *get_stack();

protected:

private:

nsapi_error_t connect_async(const char *ssid,
const char *pass,
nsapi_security_t security = NSAPI_SECURITY_NONE,
uint8_t channel = 0,
void *data = NULL,
unsigned timeout = 0);

bool start(bool debug);
bool stop();

char _mac_addr_str[18];
// Private context to share between C and C++ calls
PrivContext* _priv_context;
const char *_ssid;
const char *_pass;
char _ip_address[IPADDR_STRLEN_MAX];
char _netmask[IPADDR_STRLEN_MAX];
char _gateway[IPADDR_STRLEN_MAX];
nsapi_security_t _security;
uint8_t _channel;
bool _use_dhcp;
int _timeout;
// Event queue when the driver context need to be used
EventQueue* _odin_event_queue;
int32_t target_id;
// Event queue for sending start up and connection events from driver to this class
MsgQueue _event_queue;
// Message queue for sending scan events from driver to this class
osMessageQId _scan_msg_queue_id;
osMessageQDef_t _queue_def;

enum OdinWifiState {
S_NOT_INITIALISED = 1,
S_WAIT_START,
S_STARTED,
S_WAIT_STOP,

S_STA_IDLE,
S_STA_WAIT_CONNECT,
S_STA_CONNECTED,
S_STA_DISCONNECTED_WAIT_CONNECT,
S_STA_CONNECTION_FAIL_WAIT_DISCONNECT,
//S_STA_LINK_LOSS_WAIT_DISCONNECT,
S_STA_WAIT_DISCONNECT,

S_AP_IDLE,
S_AP_WAIT_START,
S_AP_STARTED,
S_AP_WAIT_STOP,
S_AP_FAIL_WAIT_STOP,
S_AP_WAIT_DRV_STOP,
S_AP_WAIT_DRV_START,

S_INVALID
};

struct sta_s {
const char *ssid;
const char *passwd;
nsapi_security_t security;
uint8_t channel;
bool use_dhcp;
int timeout_ms;
char ip_address[IPADDR_STRLEN_MAX];
char netmask[IPADDR_STRLEN_MAX];
char gateway[IPADDR_STRLEN_MAX];
};

struct ap_s {
const char *ssid;
const char *passwd;
nsapi_security_t security;
uint8_t channel;
bool use_dhcp;

char ip_address[IPADDR_STRLEN_MAX];
char netmask[IPADDR_STRLEN_MAX];
char gateway[IPADDR_STRLEN_MAX];

int cnt_connected;

nsapi_error_t error_code;
};

struct scan_cache_s {
int count;
uint8_t last_channel;
cbWLAN_MACAddress bssid[ODIN_WIFI_SCAN_CACHE_SIZE];
};

OdinWifiState entry_connect_fail_wait_disconnect();
OdinWifiState entry_wait_connect();
OdinWifiState entry_wait_disconnect();
//OdinWifiState entry_link_loss_wait_disconnect(void);
OdinWifiState entry_ap_wait_start();
OdinWifiState entry_ap_started();
OdinWifiState entry_ap_wait_stop();
OdinWifiState entry_ap_fail_wait_stop();
OdinWifiState entry_ap_wait_drv_stop();
OdinWifiState entry_ap_wait_drv_start();

void handle_in_msg();
void handle_cached_msg();

void handle_user_connect(user_connect_s *user_connect);
void handle_user_disconnect();
void handle_user_scan(user_scan_s *user_scan);
void handle_user_connect_timeout();
void handle_user_stop();

void handle_user_ap_start(user_ap_start_s *user_ap_start);
void handle_user_ap_stop();

void handle_wlan_status_started(wlan_status_started_s *start);
void handle_wlan_status_stopped(void);
void handle_wlan_status_error(void);
void handle_wlan_status_connecting(void);
void handle_wlan_status_connected(wlan_status_connected_s *wlan_connect);
void handle_wlan_status_connection_failure(wlan_status_connection_failure_s *connect_failure);
void handle_wlan_status_disconnected(void);
void handle_wlan_scan_indication();

void handle_wlan_status_ap_up();
void handle_wlan_status_ap_down();

void init(bool debug);
nsapi_error_t wlan_set_channel(uint8_t channel);
nsapi_error_t wlan_connect(
const char *ssid,
const char *passwd,
nsapi_security_t security);
nsapi_error_t wlan_ap_start(
const char *ssid,
const char *pass,
nsapi_security_t security,
uint8_t channel);

void timeout_user_connect();
void update_scan_list(cbWLAN_ScanIndicationInfo *scan_info);
void send_user_response_msg(unsigned int type, nsapi_error_t error_code);
void wlan_status_indication(cbWLAN_StatusIndicationInfo status, void *data);
void wlan_scan_indication(cbWLAN_ScanIndicationInfo *scan_info, cb_boolean is_last_result);

static bool _wlan_initialized; // Controls that cbWLAN is initiated only once
static emac_interface_t* _emac; // Not possible to remove added interfaces to the network stack => static and re-use
static int32_t _target_id;

OdinWifiState _state;
OdinWifiState _state_sta;
OdinWifiState _state_ap;

struct sta_s _sta;
struct ap_s _ap;
nsapi_stack_t _stack;
char _mac_addr_str[ODIN_WIFI_MAX_MAC_ADDR_STR];

cbWLAN_StatusConnectedInfo _wlan_status_connected_info;
cbWLAN_StatusDisconnectedInfo _wlan_status_disconnected_info;

bool _scan_active;
WiFiAccessPoint *_scan_list;
nsapi_size_t _scan_list_size;
nsapi_size_t _scan_list_cnt;
struct scan_cache_s _scan_cache;

friend struct wlan_callb_s;

Mutex _mutex;
Queue<odin_wifi_msg_s, 6> _in_queue;
Queue<odin_wifi_msg_s, 1> _out_queue;
Queue<odin_wifi_msg_s, 1> _cache_queue;
MemoryPool<odin_wifi_msg_s, 7> *_msg_pool;
Thread _thread;
//Timeout _timeout; //Randomly lost interrupts/callbacks; replaced by Timer
Timer _timer;

bool _debug;
int _dbg_timeout;
};

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
* SPDX-License-Identifier: LicenseRef-PBL
*
* This file and the related binary are licensed under the
Expand Down Expand Up @@ -65,6 +65,11 @@

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

#define BD_ADDR_IS_STATIC_RANDOM(BdAddress) ((BdAddress[0] & 0xC0) == 0xC0)
#define BD_ADDR_IS_NON_RESOLVABLE(BdAddress) ((BdAddress[0] & 0xC0) == 0x00)
#define BD_ADDR_IS_RESOLVABLE(BdAddress) ((BdAddress[0] & 0xC0) == 0x40)

#define BT_INVALID_STATIC_LINK_KEY (0)
/*===========================================================================
* TYPES
*=========================================================================*/
Expand Down
Loading

0 comments on commit 5d0ce3c

Please sign in to comment.