NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Wed Jun 17 20:56:15 2015 +0000
Parent:
6:7437289cb2e9
Child:
8:4b7f97a5597b
Commit message:
Create WiFi base with connection parameters

Changed in this revision

NetworkInterface.h Show annotated file Show diff for this revision Revisions of this file
SocketInterface.h Show annotated file Show diff for this revision Revisions of this file
WiFiInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/NetworkInterface.h	Mon Jun 01 16:21:59 2015 -0500
+++ b/NetworkInterface.h	Wed Jun 17 20:56:15 2015 +0000
@@ -17,83 +17,66 @@
 #ifndef NETWORKINTERFACE_H
 #define NETWORKINTERFACE_H
 
+#include "stdint.h"
+
 /** NetworkInterface class.
- *   This is a common interface that is shared between all hardware that connect
- *   to a network over IP.
+    This is a common interface that is shared between all hardware that connect
+    to a network over IP.
  */
 class NetworkInterface
 {
 public:
 
-    /**
-     *    Initialize the network interface with DHCP.
-     *
-     *    \returns 0 on success, a negative number on failure
+    /** Initialize the network interface with DHCP.
+        @returns 0 on success, a negative number on failure
      */
-    virtual int init(void) const = 0;
+    virtual int32_t init(void) const = 0;
 
-    /**
-     *    Initialize the network interface with a static IP address.
-     *
-     *    @param ip The static IP address to use
-     *    @param mask The IP address mask
-     *    @param gateway The gateway to use
-     *
-     *    \returns 0 on success, a negative number on failure
+    /** Initialize the network interface with a static IP address.
+        @param ip The static IP address to use
+        @param mask The IP address mask
+        @param gateway The gateway to use
+        @returns 0 on success, a negative number on failure
      */
-    int init(const char *ip, const char *mask, const char *gateway) const = 0;
+    virtual int32_t init(const char *ip, const char *mask, const char *gateway) const = 0;
+    
 
-    /**
-     *    Start the interface, using DHCP if needed.
-     *
-     *    @param timeout_ms Time in miliseconds to wait while attempting to connect before timing out
-     *
-     *    \returns 0 on success, a negative number on failure
+    /** Start the interface, using DHCP if needed.
+        @param timeout_ms Time in miliseconds to wait while attempting to connect before timing out
+        @returns 0 on success, a negative number on failure
      */
-    virtual int connect(const unsigned int timeout_ms=15000) const = 0;
+    virtual int32_t connect(uint32_t timeout_ms=15000) const = 0;
 
-    /**
-     *    Stop the interface, bringing down dhcp if necessary.
-     *
-     *    \returns 0 on success, a negative number on failure
+    /** Stop the interface, bringing down dhcp if necessary.
+        @returns 0 on success, a negative number on failure
      */
-    virtual int disconnect(void) const = 0;
+    virtual int32_t disconnect(void) const = 0;
 
-    /**
-     *    Get the current IP address.
-     *
-     *    \returns a pointer to a string containing the IP address.
+    /** Get the current IP address.
+        @returns a pointer to a string containing the IP address.
      */
     virtual char *getIPAddress(void) const = 0;
 
-    /**
-     *    Get the current gateway address.
-     *
-     *    \returns a pointer to a string containing the gateway address.
+    /** Get the current gateway address.
+        @returns a pointer to a string containing the gateway address.
      */
     virtual char *getGateway(void) const = 0;
 
 
-    /**
-     *    Get the current network mask.
-     *
-     *    \returns a pointer to a string containing the network mask.
+    /** Get the current network mask.
+        @returns a pointer to a string containing the network mask.
      */
     virtual char *getNetworkMask(void) const = 0;
 
-    /**
-     *    Get the devices MAC address.
-     *
-     *    \returns a pointer to a string containing the mac address.
+    /** Get the devices MAC address.
+        @returns a pointer to a string containing the mac address.
      */
     virtual char *getMACAddress(void) const = 0;
 
-    /**
-     *    Get the current status of the interface connection.
-     *
-     *    \returns true if connected, false otherwise.
+    /** Get the current status of the interface connection.
+        @returns true if connected, a negative number on failure
      */
-    virtual int isConnected(void) const = 0;
+    virtual int32_t isConnected(void) const = 0;
 };
 
 #endif
--- a/SocketInterface.h	Mon Jun 01 16:21:59 2015 -0500
+++ b/SocketInterface.h	Wed Jun 17 20:56:15 2015 +0000
@@ -24,50 +24,63 @@
 class SocketInterface {
 
 public:
-    /**
-     *    This enum defines the possible socket protocol families.
-     */
-    enum ProtocolFamily {
-        AF_INET,    /**< IPv4 */
-        AF_INET6,   /**< IPV6 */
-        AF_UNIX     /**< Local socket (using a file) */
-    };
-    
-    /**
-     *    This enum defines the possible socket types.
-     */
-    enum SockType {
-        SOCK_STREAM,    /**< Stream socket, generally used for TCP */
-        SOCK_DGRAM,     /**< Datagram socket, generally used for UDP */
-        SOCK_SEQPACKET, /**< Reliable sequenced packet service */
-        SOCK_RAW        /**< Raw protocols atop the network layer */
-    };
-
-    /**
-     *    Configure the socket's protocol and type.
-     *
-     *    @param protocol The protocol to use.
-     *    @param type The type of socket to use.
-     */
-    virtual int config(ProtocolFamily protocol, SockType type) = 0;
-    
-    /** 
-     *    Set blocking or non-blocking mode of the socket and a timeout on
-     *    blocking socket operations.
-     *    
-     *    @param blocking true for blocking mode, false for non-blocking mode.
-     *    @param timeout timeout in ms [Default: (1500)ms].
-     */
-    virtual void setBlocking(bool blocking, unsigned int timeout=1500) = 0;
-    
-    /*
-        "options" functions here? Not familiar with this, need to discuss
-    */
-    
-    /**
-     *    Close the socket
-     */
-    virtual void close();
+//    /** This enum defines the possible socket domain types.
+//     */
+//    typedef enum {
+//        AF_INET,        /*!< IPv4 */
+//        AF_INET6,       /*!< IPV6 */
+//        AF_UNIX         /*!< Local socket (using a file) */
+//    } socket_domain_t;
+//    
+//    /** This enum defines the possible socket types.
+//     */
+//    typedef enum {
+//        SOCK_STREAM,    /*!< Reliable stream-oriented service or Stream Sockets */
+//        SOCK_DGRAM,     /**< Datagram service or Datagram Sockets */
+//        SOCK_SEQPACKET, /*!< Reliable sequenced packet service */
+//        SOCK_RAW        /*!< Raw protocols atop the network layer */
+//    } socket_type_t;
+//
+//    /** This enum defines the ip protocols
+//     */
+//    typedef enum {
+//        IPPROTO_TCP,    /*!< Socket connection over TCP */
+//        IPPROTO_UDP,    /*!< Socket connection over UDP */
+//        IPPROTO_SCTP    /*!< Socket connection over SCTP */
+//        IPPROTO_DCCP,   /*!< Socket connection over DCCP */
+//    } socket_type_t;
+//
+//    /** Configure the socket's protocol and type.
+//        @param protocol The protocol to use.
+//        @param type The type of socket to use.
+//        @returns 0 on success, a negative number on failure
+//     */
+//    virtual int32_t socket(socket_domain_t protocol, socket_type_t type, ) const = 0;
+//    
+//    /** Configure the socket's protocol and type.
+//        @param protocol The protocol to use.
+//        @param type The type of socket to use.
+//        @returns 0 on success, a negative number on failure
+//     */
+//    virtual int bind(const struct sockaddr *my_addr, socklen_t addrlen);
+//    
+//    /** 
+//     *    Set blocking or non-blocking mode of the socket and a timeout on
+//     *    blocking socket operations.
+//     *    
+//     *    @param blocking true for blocking mode, false for non-blocking mode.
+//     *    @param timeout timeout in ms [Default: (1500)ms].
+//     */
+//    virtual void setBlocking(bool blocking, unsigned int timeout=1500) = 0;
+//    
+//    /*
+//        "options" functions here? Not familiar with this, need to discuss
+//    */
+//    
+//    /**
+//     *    Close the socket
+//     */
+//    virtual void close();
 
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiFiInterface.h	Wed Jun 17 20:56:15 2015 +0000
@@ -0,0 +1,52 @@
+/* WiFiInterface Base Class
+ * Copyright (c) 2015 ARM Limited
+ *
+ * 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 WIFIINTERFACE_H
+#define WIFIINTERFACE_H
+
+#include "NetworkInterface.h"
+
+/* wifi_security_t enum for encryption types
+ */
+typedef enum wifi_security_t {
+    WI_NONE = 0,    /*!< No security for connection */
+    WI_WEP,         /*!< WEP  encryption */
+    WI_WPA,         /*!< WPA  encryption */
+    WI_WPA2,        /*!< WPA2 encryption */
+} wifi_security_t;
+
+/** WiFiInterface class.
+    This is a common interface to handle how WiFi connects to an access point
+ */
+class WiFiInterface : public NetworkInterface
+{
+public:
+
+    // make sure to import the base symbol that needs an implementation for classes that have ap and phrase in the constructor
+    using NetworkInterface::connect;
+        
+    /** Start the interface using ap name, phrase and security attributes
+        @param ap Name of the network the radio should connect to
+        @param pass_pharase The security phrase needed for connecting to the network
+        @param security Type of encryption the network requires for connection
+        @param timeout_ms Time in miliseconds to wait while attempting to connect before timing out
+        @returns 0 on success, a negative number on failure
+     */
+    virtual int32_t connect(const char *ap, const char *pass_phrase = 0, wifi_security_t security = WI_NONE, uint32_t timeout_ms = 15000) const = 0;
+    
+};
+
+#endif