LWIPBP3595Interface library for mbed-os.
Dependents: LWIPBP3595Interface_STA_for_mbed-os
Fork of LWIPBP3595Interface by
Diff: LWIPBP3595Interface.h
- Revision:
- 3:2ff2514e4fca
- Parent:
- 2:c7e325599570
- Child:
- 4:b49b4b36aaa4
--- a/LWIPBP3595Interface.h Tue Sep 13 09:31:41 2016 +0000 +++ b/LWIPBP3595Interface.h Thu Oct 27 09:30:15 2016 +0000 @@ -31,32 +31,132 @@ class LWIPBP3595Interface : public WiFiInterface { public: - /** Start the interface + /** LWIPBP3595Interface lifetime + */ + LWIPBP3595Interface(); + + virtual ~LWIPBP3595Interface(); + + /** 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. * - * Attempts to connect to a WiFi network. If passphrase is invalid, - * NSAPI_ERROR_AUTH_ERROR is returned. + * @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 + * + * Requires that the network is disconnected + * + * @param dhcp False to disable dhcp (defaults to enabled) + * @return 0 on success, negative error code on failure + */ + virtual int set_dhcp(bool dhcp); + + /** 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 set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_WPA2); + + /** 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); + + /** Gets the current radio signal strength for active connection + * + * @return Connection strength in dBm (negative value), + * or 0 if measurement impossible */ - virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_WPA2); + virtual int8_t get_rssi(); + + /** 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_WPA2, + 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, negative on failure */ virtual int disconnect(); - /** Get the internally stored IP address - * @return IP address of the interface or null if not yet connected + /** Scan for available networks + * + * The scan will + * 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); + + /** 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 internally stored MAC address - * @return MAC address of the interface + /** 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_mac_address(); + virtual const char *get_netmask(); + + /** Get the local gateways + * + * @return Null-terminated representation of the local gateway + * or null if no network mask has been recieved + */ + virtual const char *get_gateway(); protected: /** Provide access to the underlying stack @@ -64,6 +164,16 @@ * @return The underlying network stack */ virtual NetworkStack *get_stack(); + + bool _dhcp; + char _ip_address[IPADDR_STRLEN_MAX]; + char _netmask[NSAPI_IPv4_SIZE]; + char _gateway[NSAPI_IPv4_SIZE]; + +private: + char *_ssid; + char *_pass; + nsapi_security_t _security; };