Skip to content

Ublox drivers #2977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Unless specifically indicated otherwise in a file, files are licensed under the
Permissive Binary License1.0 (PBL-1.0) as can be found in: LICENSE-permissive-binary-license-1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Permissive Binary License

Version 1.0, September 2015

Redistribution. Redistribution and use in binary form, without
modification, are permitted provided that the following conditions are
met:

1) Redistributions must reproduce the above copyright notice and the
following disclaimer in the documentation and/or other materials
provided with the distribution.

2) Unless to the extent explicitly permitted by law, no reverse
engineering, decompilation, or disassembly of this software is
permitted.

3) Redistribution as part of a software development kit must include the
accompanying file named “DEPENDENCIES” and any dependencies listed in
that file.

4) Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

Limited patent license. The copyright holders (and contributors) grant a
worldwide, non-exclusive, no-charge, royalty-free patent license to
make, have made, use, offer to sell, sell, import, and otherwise
transfer this software, where such license applies only to those patent
claims licensable by the copyright holders (and contributors) that are
necessarily infringed by this software. This patent license shall not
apply to any combinations that include this software. No hardware is
licensed hereunder.

If you institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the software
itself infringes your patent(s), then your rights granted under this
license shall terminate as of the date such litigation is filed.

DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _ODIN_W2_MBEDTLS_CONFIG_H_
#define _ODIN_W2_MBEDTLS_CONFIG_H_

#define MBEDTLS_ARC4_C
#define MBEDTLS_DES_C
#define MBEDTLS_MD4_C
#define MBEDTLS_MD5_C
#define MBEDTLS_SHA1_C

#endif /* _ODIN_W2_MBEDTLS_CONFIG_H_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/* ODIN-W2 implementation of WiFiInterface
* Copyright (c) 2016 u-blox Malm� AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ODIN_WIFI_INTERFACE_H
#define ODIN_WIFI_INTERFACE_H

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

#include "rtos.h"
#include "emac_api.h"
#include "nsapi_types.h"
#include "lwip/netif.h"

typedef Queue<void*, 1> MsgQueue;

class OdinWiFiInterface;

struct PrivContext;

/** OdinWiFiInterface class
* Implementation of the WiFiInterface for the ODIN-W2 module
*/
class OdinWiFiInterface : public WiFiInterface
{
public:
/** OdinWiFiInterface lifetime
*/
OdinWiFiInterface();

OdinWiFiInterface(bool debug);

~OdinWiFiInterface();

/** Set the WiFi network credentials
*
* @param ssid Name of the network to connect to
* @param pass Security passphrase to connect to the network
* @param security Type of encryption for connection
* (defaults to NSAPI_SECURITY_NONE)
* @return 0 on success, or error code on failure
*/
virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);

/** Set the WiFi network channel
*
* @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 int set_channel(uint8_t channel);

/** Start the interface
*
* Attempts to connect to a WiFi network.
*
* @param ssid Name of the network to connect to
* @param pass Security passphrase to connect to the network
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
* @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 int connect(const char *ssid,
const char *pass,
nsapi_security_t security = NSAPI_SECURITY_NONE,
uint8_t channel = 0);

/** Start the interface
*
* Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
* If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
*
* @return 0 on success, negative error code on failure
*/
virtual int connect();

/** Stop the interface
*
* @return 0 on success, or error code on failure
*/
virtual int disconnect();

/** Get the local MAC address
*
* Provided MAC address is intended for info or debug purposes and
* may not be provided if the underlying network interface does not
* provide a MAC address
*
* @return Null-terminated representation of the local MAC address
* or null if no MAC address is available
*/
virtual const char *get_mac_address();

/** Get the local IP address
*
* @return Null-terminated representation of the local IP address
* or null if no IP address has been recieved
*/
virtual const char *get_ip_address();

/** Get the local network mask
*
* @return Null-terminated representation of the local network mask
* or null if no network mask has been recieved
*/
virtual const char *get_netmask();

/** Get the local gateway
*
* @return Null-terminated representation of the local gateway
* or null if no network mask has been recieved
*/
virtual const char *get_gateway();

/** Set a static IP address
*
* Configures this network interface to use a static IP address.
* Implicitly disables DHCP, which can be enabled in set_dhcp.
* Requires that the network is disconnected.
*
* @param address Null-terminated representation of the local IP address
* @param netmask Null-terminated representation of the local network mask
* @param gateway Null-terminated representation of the local gateway
* @return 0 on success, negative error code on failure
*/
virtual int set_network(const char *ip_address, const char *netmask, const char *gateway);

/** Enable or disable DHCP on the network
*
* Enables DHCP on connecting the network. Defaults to enabled unless
* a static IP address has been assigned. Requires that the network is
* disconnected.
*
* @param dhcp True to enable DHCP
* @return 0 on success, negative error code on failure
*/
virtual int set_dhcp(bool dhcp);

/** Gets the current radio signal strength for active connection
*
* @return Connection strength in dBm (negative value),
* or 0 if measurement impossible
*/
virtual int8_t get_rssi();

/** Scan for available networks
*
* If the network interface is set to non-blocking mode, scan will attempt to scan
* for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
* is attached, the callback will be called when the operation has completed.
*
* @param ap Pointer to allocated array to store discovered AP
* @param count Size of allocated @a res array, or 0 to only count available AP
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
* see @a nsapi_error
*/
virtual int scan(WiFiAccessPoint *res, unsigned count);

/** Sets timeout for connection setup. Note that the time for DHCP retrieval is not included.
*
* @param timeout Timeout in ms. Use 0 for waiting forever. The timeout might take up to X sec longer than
* 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 NetworkStack *get_stack();

protected:

private:

int 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;
// Event queue for sending scan events from driver to this class
MsgQueue _scan_event_queue;
};

#endif
Loading