emw3162 driver for mbed os 5

Fork of emw3162-driver by Maggie Mei

Revision:
3:a6f80a95b039
Parent:
2:fb6251306b21
--- a/EMW3162Interface.h	Mon Nov 14 02:30:49 2016 +0000
+++ b/EMW3162Interface.h	Thu Nov 17 03:52:22 2016 +0000
@@ -17,8 +17,9 @@
 #ifndef EMW3162_INTERFACE_H
 #define EMW3162_INTERFACE_H
 
-#include "NetworkSocketAPI/NetworkStack.h"
-#include "NetworkSocketAPI/WiFiInterface.h"
+#include "mbed.h"
+//#include "NetworkSocketAPI/NetworkStack.h"
+//#include "NetworkSocketAPI/WiFiInterface.h"
 #include "EMW3162.h"
 
 
@@ -39,18 +40,44 @@
 
     /** Start the interface
      *
-     *  Attempts to connect to a WiFi network. If passphrase is invalid,
-     *  NSAPI_ERROR_AUTH_ERROR is returned.
+     *  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();
+
+    /** 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   This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED
+     *  @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);
+
+    /** 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
-     *  @return          0 on success, negative error code on failure
+     *                   (defaults to NSAPI_SECURITY_NONE)
+     *  @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);
+    virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
+
+    /** Set the WiFi network channel - NOT SUPPORTED
+     *
+     * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED
+     *
+     *  @param channel   Channel on which the connection is to be made, or 0 for any (Default: 0)
+     *  @return          Not supported, returns NSAPI_ERROR_UNSUPPORTED
+     */
+    virtual int set_channel(uint8_t channel);
 
     /** Stop the interface
      *  @return             0 on success, negative on failure
@@ -67,6 +94,38 @@
      */
     virtual const char *get_mac_address();
 
+    /** 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();
+
+    /** 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();
+
+    /** Gets the current radio signal strength for active connection
+     *
+     * @return          Connection strength in dBm (negative value)
+     */
+    virtual int8_t get_rssi();
+
+    /** Scan for available networks
+     *
+     * This function will block.
+     *
+     * @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);
+    
 protected:
     /** Open a socket
      *  @param handle       Handle in which to store new socket
@@ -112,7 +171,7 @@
      *  @note This call is not-blocking, if this call would block, must
      *        immediately return NSAPI_ERROR_WOULD_WAIT
      */
-    virtual int socket_accept(void **handle, void *server);
+    virtual int socket_accept(void *handle, void **socket, SocketAddress *address);
 
     /** Send data to the remote host
      *  @param handle       Socket handle
@@ -179,6 +238,11 @@
     EMW3162 _esp;
     bool _ids[EMW3162_SOCKET_COUNT];
 
+    char ap_ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
+    nsapi_security_t ap_sec;
+    uint8_t ap_ch;
+    char ap_pass[64]; /* The longest allowed passphrase */
+
     void event();
     struct {
         void (*callback)(void *);