NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Revision 51:f2a088d58051, committed 2016-02-25
- Comitter:
- Christopher Haster
- Date:
- Thu Feb 25 04:11:11 2016 -0600
- Parent:
- 20:3ad72f5406bf
- Parent:
- 50:3fa3b0405df9
- Child:
- 52:52a6c4ea7128
- Commit message:
- Merged api-changes
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DnsQuery.lib Thu Feb 25 04:11:11 2016 -0600 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/geky/code/DnsQuery/#fc334e844124
--- a/EthernetInterface.h Fri Dec 25 19:51:33 2015 +0000 +++ b/EthernetInterface.h Thu Feb 25 04:11:11 2016 -0600 @@ -14,29 +14,27 @@ * limitations under the License. */ -#ifndef ETHERNETINTERFACE_H -#define ETHERNETINTERFACE_H +#ifndef ETHERNET_INTERFACE_H +#define ETHERNET_INTERFACE_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; -/** EthernetInterface class. - This is a common interface to handle how ethernet connects to a router +/** EthernetInterface class + * Common interface that is shared between ethernet hardware */ class EthernetInterface : public NetworkInterface { public: + /** Start the interface + * @return 0 on success + */ + virtual int32_t connect() = 0; - // make sure to import the base symbol that needs an implementation for classes that have ap and phrase in the constructor - using NetworkInterface::connect; + /** Stop the interface + * @return 0 on success + */ + virtual int32_t disconnect() = 0; }; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NetworkInterface.cpp Thu Feb 25 04:11:11 2016 -0600 @@ -0,0 +1,88 @@ +/* NetworkInterface 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. + */ + +#include "NetworkInterface.h" +#include "UDPSocket.h" +#include "DnsQuery.h" +#include <string.h> + +NetworkInterface::NetworkInterface() +{ + memset(_ip_address, 0, NS_IP_SIZE); + memset(_network_mask, 0, NS_IP_SIZE); + memset(_gateway, 0, NS_IP_SIZE); +} + +void NetworkInterface::useDHCP() +{ + memset(_ip_address, 0, NS_IP_SIZE); + memset(_network_mask, 0, NS_IP_SIZE); + memset(_gateway, 0, NS_IP_SIZE); +} + +void NetworkInterface::setIPAddress(const char *ip) +{ + strcpy(_ip_address, ip); +} + +void NetworkInterface::setNetworkMask(const char *mask) +{ + strcpy(_network_mask, mask); +} + +void NetworkInterface::setGateway(const char *gateway) +{ + strcpy(_gateway, gateway); +} + +const char *NetworkInterface::getIPAddress() +{ + if (_ip_address[0]) { + return _ip_address; + } else { + return 0; + } +} + +const char *NetworkInterface::getNetworkMask() +{ + if (_network_mask[0]) { + return _network_mask; + } else { + return 0; + } +} + +const char *NetworkInterface::getGateway() +{ + if (_gateway[0]) { + return _gateway; + } else { + return 0; + } +} + +bool NetworkInterface::isConnected() +{ + return getIPAddress() != 0; +} + +int32_t NetworkInterface::getHostByName(const char *name, char *ip) +{ + UDPSocket sock(this); + DnsQuery dns(&sock, name, ip); + return 0; +}
--- a/NetworkInterface.h Fri Dec 25 19:51:33 2015 +0000 +++ b/NetworkInterface.h Thu Feb 25 04:11:11 2016 -0600 @@ -14,92 +14,114 @@ * limitations under the License. */ -#ifndef NETWORKINTERFACE_H -#define NETWORKINTERFACE_H +#ifndef NETWORK_INTERFACE_H +#define NETWORK_INTERFACE_H -#include "stdint.h" #include "SocketInterface.h" -#include <map> +#include "stdint.h" + + +/** Maximum storage needed for IP address and MAC addresses + */ +#define NS_IP_SIZE 16 +#define NS_MAC_SIZE 18 -/** NetworkInterface class. - This is a common interface that is shared between all hardware that connect - to a network over IP. +/** Inexhaustive enum of standardized error codes + */ +enum ns_error_t { + NS_ERROR_TIMEOUT = -3001, + NS_ERROR_NO_CONNECTION = -3002, + NS_ERROR_NO_SOCKET = -3003, + NS_ERROR_NO_ADDRESS = -3004, + NS_ERROR_NO_MEMORY = -3005, + NS_ERROR_DNS_FAILURE = -3006, + NS_ERROR_DHCP_FAILURE = -3007, + NS_ERROR_AUTH_FAILURE = -3008, + NS_ERROR_DEVICE_ERROR = -3009 +}; + + +/** NetworkInterface class + * Common interface that is shared between all hardware that + * can connect to a network over IP. */ class NetworkInterface { public: - - /** Initialize the network interface with DHCP. - @returns 0 on success, a negative number on failure + /** Enables DHCP and clears any static address + * DHCP resolution does not occur until connect call + * DHCP is enabled by default */ - virtual int32_t init(void) = 0; + virtual void useDHCP(); - /** 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 + /** Set the static IP address of the network interface + * @param ip Static IP address, copied internally */ - virtual int32_t init(const char *ip, const char *mask, const char *gateway) = 0; - + virtual void setIPAddress(const char *ip); + + /** Set the static network mask of the network interface + * @param mask Static network mask, copied internally + */ + virtual void setNetworkMask(const char *mask); - /** 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 + /** Set the static gateway of the network interface + * @param gateway Gateway address, copied internally */ - virtual int32_t connect(uint32_t timeout_ms = 15000) = 0; + virtual void setGateway(const char *gateway); - /** Stop the interface, bringing down dhcp if necessary. - @returns 0 on success, a negative number on failure + /** Get the IP address + * @return IP address of the interface */ - virtual int32_t disconnect(void) = 0; + virtual const char *getIPAddress(); - /** Get the current IP address. - @returns a pointer to a string containing the IP address. + /** Get the network mask + * @return Network mask of the interface */ - virtual char *getIPAddress(void) = 0; + virtual const char *getNetworkMask(); - /** Get the current gateway address. - @returns a pointer to a string containing the gateway address. + /** Get the gateway + * @return Gateway address of the interface */ - virtual char *getGateway(void) const = 0; + virtual const char *getGateway(); - - /** Get the current network mask. - @returns a pointer to a string containing the network mask. + /** Get the current MAC address + * @return String MAC address of the interface */ - virtual char *getNetworkMask(void) const = 0; + virtual const char *getMACAddress() = 0; - /** Get the devices MAC address. - @returns a pointer to a string containing the mac address. + /** Get the current status of the interface + * @return true if connected */ - virtual char *getMACAddress(void) const = 0; + virtual bool isConnected(); - /** Get the current status of the interface connection. - @returns true if connected, a negative number on failure + /** Looks up the specified host's IP address + * @param name URL of host + * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE + * @return 0 on success */ - virtual int32_t isConnected(void) = 0; - - /** Allocate space for a socket. - @param The type of socket you want to open, SOCK_TCP or SOCK_UDP - @returns a pointer to the allocated socket. + int32_t getHostByName(const char *name, char *ip); + +protected: + NetworkInterface(); + + friend class Socket; + + /** Internally create a socket + * @param proto The type of socket to open, SOCK_TCP or SOCK_UDP + * @return The allocated socket */ - virtual SocketInterface* allocateSocket(socket_protocol_t socketProtocol) = 0; - - /** Deallocate space for a socket. - @param An allocated SocketInterface - @returns 0 if object is destroyed, -1 otherwise + virtual SocketInterface *createSocket(socket_protocol_t proto) = 0; + + /** Internally destroy a socket + * @param socket An allocated SocketInterface + * @returns 0 on success */ - virtual int deallocateSocket(SocketInterface* socket) = 0; - -protected: - /** Map used to keep track of all SocketInterface instances */ - std::map<uint32_t, SocketInterface*> sockets; - - /** Counter used to create unique handles for new sockets. - Should be incremented whenever a new socket is created. - */ - uint32_t uuidCounter; + virtual void destroySocket(SocketInterface *socket) = 0; + +private: + char _ip_address[NS_IP_SIZE]; + char _network_mask[NS_IP_SIZE]; + char _gateway[NS_IP_SIZE]; }; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Socket.cpp Thu Feb 25 04:11:11 2016 -0600 @@ -0,0 +1,166 @@ +/* Socket + * 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. + */ + +#include "Socket.h" +#include <string.h> + +Socket::Socket(NetworkInterface *iface, socket_protocol_t proto) + : _iface(iface) + , _proto(proto) + , _socket(0) +{ + memset(_ip_address, 0, NS_IP_SIZE); + _port = 0; +} + +Socket::~Socket() +{ + if (_socket) { + close(); + } +} + +int32_t Socket::setURL(const char *url) +{ + int32_t err = _iface->getHostByName(url, _ip_address); + if (err) { + return err; + } + + if (_socket) { + _socket->setIPAddress(_ip_address); + } + + return 0; +} + +void Socket::setIPAddress(const char *ip) +{ + strcpy(_ip_address, ip); + + if (_socket) { + _socket->setIPAddress(_ip_address); + } +} + +void Socket::setPort(uint16_t port) +{ + _port = port; + + if (_socket) { + _socket->setPort(_port); + } +} + +const char *Socket::getIPAddress() const +{ + if (_ip_address[0]) { + return _ip_address; + } else { + return 0; + } +} + +uint16_t Socket::getPort() const +{ + return _port; +} + +bool Socket::isConnected() +{ + if (!_socket) { + return false; + } + + return _socket->isConnected(); +} + +int32_t Socket::open(const char *address, uint16_t port) +{ + int32_t err; + + err = close(); + if (err) { + return err; + } + + if (address) { + err = setURL(address); + if (err) { + return err; + } + } + + if (port) { + setPort(port); + } + + if (!getIPAddress() || !getPort()) { + return NS_ERROR_NO_ADDRESS; + } + + _socket = _iface->createSocket(_proto); + if (!_socket) { + return NS_ERROR_NO_SOCKET; + } + + err = _socket->open(_ip_address, _port); + + if (err) { + _iface->destroySocket(_socket); + } + + return err; +} + +int32_t Socket::close() +{ + if (!_socket) { + return 0; + } + + int32_t err = _socket->close(); + + if (!err) { + _iface->destroySocket(_socket); + } + + return err; +} + +int32_t Socket::send(const void *data, uint32_t size) +{ + if (!_socket) { + return NS_ERROR_NO_CONNECTION; + } + return _socket->send(data, size); +} + +int32_t Socket::recv(void *data, uint32_t size, bool blocking) +{ + if (!_socket) { + return NS_ERROR_NO_CONNECTION; + } + + while (true) { + int32_t recv = _socket->recv(data, size); + + if (recv != 0 || !blocking) { + return recv; + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Socket.h Thu Feb 25 04:11:11 2016 -0600 @@ -0,0 +1,103 @@ +/* Socket + * 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 SOCKET_H +#define SOCKET_H + +#include "NetworkInterface.h" + +/** Abstract socket class + * API for handling general sockets. Supports IP address operations + * and sending/recieving data. + */ +class Socket +{ +public: + /** Set the URL of the socket + * Performs DNS lookup if necessary + * @param url URL to connect to + * @return 0 on success + */ + int32_t setURL(const char *url); + + /** Set the IP address of the socket + * @param ip IP address to connect to, copied internally + */ + void setIPAddress(const char *ip); + + /** Set the port of the socket + * @param port Port to connect to + */ + void setPort(uint16_t port); + + /** Gets the IP address + * @return IP address to connect to + */ + const char *getIPAddress() const; + + /** Gets the port + * @return Port to connect to + */ + uint16_t getPort() const; + + /** Returns status of socket + * @return true if connected + */ + bool isConnected(); + + + /** Open a connection to the underlying address + * @param address Optional URL or IP address to connect to + * @param port Optional port to connect to + * @return 0 on success + */ + int32_t open(const char *address = 0, uint16_t port = 0); + + /** Close an open connection + * @return 0 on success + */ + int32_t close(); + + /** Send data over the socket + * @param data Buffer of data to send + * @param size Size of data to send + * @return 0 on success + */ + int32_t send(const void *data, uint32_t size); + + /** Recieve data over the socket + * @param data Buffer to store recieved data + * @param size Size of provided buffer + * @param blocking If true wait for data, otherwise return 0 if no data is available + * @return Number of bytes recieved or a negative value on failure + */ + int32_t recv(void *data, uint32_t size, bool blocking = true); + + +protected: + Socket(NetworkInterface *iface, socket_protocol_t proto); + ~Socket(); + +private: + NetworkInterface *_iface; + socket_protocol_t _proto; + SocketInterface *_socket; + + char _ip_address[NS_IP_SIZE]; + uint16_t _port; +}; + +#endif
--- a/SocketInterface.h Fri Dec 25 19:51:33 2015 +0000 +++ b/SocketInterface.h Thu Feb 25 04:11:11 2016 -0600 @@ -14,139 +14,76 @@ * limitations under the License. */ -#ifndef SOCKETINTERFACE_H -#define SOCKETINTERFACE_H +#ifndef SOCKET_INTERFACE_H +#define SOCKET_INTERFACE_H #include "stdint.h" -/** This enum defines the possible socket domain types. - */ -typedef enum { - SOCK_IPV4, /*!< IPv4 */ - SOCK_IPV6, /*!< IPV6 */ -} socket_domain_t; -/** This enum defines the possible socket types. +/** Enum of socket protocols */ -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 { +enum socket_protocol_t { SOCK_TCP, /*!< Socket connection over TCP */ SOCK_UDP, /*!< Socket connection over UDP */ -} socket_protocol_t; +}; + -/** Base class that defines an endpoint (TCP/UDP/Server/Client Socket) +/** SocketInterface class + * Common interface for implementation specific sockets created through + * network interfaces. This class is used internally by the + * TCPSocket and UDPSocket classes */ -class Endpoint +class SocketInterface { public: - - /** Get the ip address of a host by DNS lookup - @param name The name of a host you need an ip address for - @return The ip address of the host otherwise NULL + /** Set the IP address of the socket + * @param ip IP address to connect to */ - virtual const char *getHostByName(const char *name) const = 0; - - /** Set the address of this endpoint - @param addr The endpoint address - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - virtual void setAddress(const char* addr) = 0; - - /** Set the port of this endpoint - @param port The endpoint port - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - virtual void setPort(uint16_t port) = 0; + virtual void setIPAddress(const char *ip) { (void)ip; } - /** Set the address and port of this endpoint - @param addr The endpoint address (supplied as an ip address). - @param port The endpoint port - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - virtual void setAddressPort(const char* addr, uint16_t port) = 0; - - /** Get the IP address of this endpoint - @return The IP address of this endpoint. + /** Set the port of the socket + * @param port Port to connect to */ - virtual const char *getAddress(void) const = 0; + virtual void setPort(uint16_t port) { (void)port; } - /** Get the port of this endpoint - @return The port of this socket + /** Status of the socket + * @return True if connected */ - virtual uint16_t getPort(void) const = 0; -protected: - const char* _addr; - uint16_t _port; -}; + virtual bool isConnected() + { + // By default return true if socket was created successfully + return true; + } -/** SocketInterface class. - * This is a common interface that is shared between all sockets that connect - * using the NetworkInterface. - */ -class SocketInterface : public Endpoint -{ -public: - /** In server mode, set which port to listen on - @param port The endpoint port - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). + /** Open a connection to the underlying address + * @param ip IP address to connect to + * @param port Port to connect to + * @return 0 on success */ - virtual int32_t bind(uint16_t port) const = 0; + virtual int32_t open(const char *ip, uint16_t port) = 0; - /** In server mode, start listening to a port - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). + /** Close an open connection + * @return 0 on success */ - virtual int32_t listen(void) const = 0; - - /** In server mode, accept an incoming connection - @param endpoint The endpoint we are listening to - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - virtual int32_t accept() const = 0; - - /** In client mode, open a connection to a remote host - @param endpoint The endpoint we want to connect to - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - virtual int32_t open() = 0; + virtual int32_t close() = 0; - /** In client or server mode send data - @param data A buffer of data to send - @param amount The amount of data to send - @param timeout_ms The longest amount of time this send can take - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - virtual int32_t send(const void *data, uint32_t amount, uint32_t timeout_ms = 15000) = 0; - - /** In client or server mode receive data - @param data a buffer to store the data in - @param amount The amount of data to receive - @param timeout_ms The longest time to wait for the data - @return The amount of data received + /** Send data + * @param data Buffer of data to send + * @param size Size of data to send + * @return 0 on success */ - virtual uint32_t recv(void *data, uint32_t amount, uint32_t timeout_ms = 15000) = 0; - - /** In client or server mode, close an open connection - @param endpoint The endpoint we want to connect to - @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - virtual int32_t close() const = 0; + virtual int32_t send(const void *data, uint32_t size) = 0; - /** Get the socket's unique handle - @return socket's handle number - */ - virtual uint32_t getHandle() const = 0; - -protected: - socket_protocol_t _type; - uint32_t _handle; + /** Receive data + * @note + * This call should return immediately with a value of 0 + * if no data is available. + * + * @param data A buffer to store the data in + * @param size Size of buffer + * @return Number of bytes received or a negative value on failure + */ + virtual int32_t recv(void *data, uint32_t size) = 0; }; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TCPSocket.h Thu Feb 25 04:11:11 2016 -0600 @@ -0,0 +1,41 @@ +/* TCPSocket + * 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 TCP_SOCKET_H +#define TCP_SOCKET_H + +#include "Socket.h" + +/** TCPSocket class + * API for handling TCP sockets. The implementation is determined + * by the interface passed during construction. + */ +class TCPSocket : public Socket +{ +public: + /** Create a socket using the specified network interface + * No network operations are performed until the socket is actually used + * @param iface The network interface to use + * @param url Optional URL to connect to, copied internally + * @param port Optional port to connect to + */ + TCPSocket(NetworkInterface *iface) + : Socket(iface, SOCK_TCP) + { + } +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UDPSocket.h Thu Feb 25 04:11:11 2016 -0600 @@ -0,0 +1,41 @@ +/* UDPSocket + * 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 UDP_SOCKET_H +#define UDP_SOCKET_H + +#include "Socket.h" + +/** UDPSocket class + * API for handling UDP sockets. The implementation is determined + * by the interface passed during construction. + */ +class UDPSocket : public Socket +{ +public: + /** Create a socket using the specified network interface + * No network operations are performed until the socket is actually used + * @param iface The network interface to use + * @param ip Optional URL to connect to, copied internally + * @param port Optional port to connect to + */ + UDPSocket(NetworkInterface *iface) + : Socket(iface, SOCK_UDP) + { + } +}; + +#endif
--- a/WiFiInterface.h Fri Dec 25 19:51:33 2015 +0000 +++ b/WiFiInterface.h Thu Feb 25 04:11:11 2016 -0600 @@ -14,39 +14,42 @@ * limitations under the License. */ -#ifndef WIFIINTERFACE_H -#define WIFIINTERFACE_H +#ifndef WIFI_INTERFACE_H +#define WIFI_INTERFACE_H #include "NetworkInterface.h" -/* wifi_security_t enum for encryption types +/** Enum for WiFi encryption types */ -typedef enum wifi_security_t { +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 +/** WiFiInterface class + * Common interface that is shared between WiFi devices */ class WiFiInterface : public NetworkInterface { public: + /** Start the interface + * @param ssid Name of the network to connect to + * @param pass Security passphrase to connect to the network + * @param security Type of encryption to connect with + * @return 0 on success + */ + virtual int32_t connect( + const char *ssid, + const char *pass, + wifi_security_t security = WI_NONE) = 0; - // 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 + /** Stop the interface + * @return 0 on success */ - virtual int32_t connect(const char *ap, const char *pass_phrase = 0, wifi_security_t security = WI_NONE, uint32_t timeout_ms = 15000) = 0; - + virtual int32_t disconnect() = 0; }; #endif