Skip to content

Commit 5b12539

Browse files
committed
wifi - Removed asynchronous functions
Current asynchronous functions do not match the blocking/attach pattern of the current codebase. Unfortunately, the asynchronous api can not be updated in the current time constraints. The async functions will be removed for now and can be reconsidered at a later date.
1 parent cca026d commit 5b12539

File tree

3 files changed

+33
-148
lines changed

3 files changed

+33
-148
lines changed

features/net/network-socket/WiFiInterface.cpp

Lines changed: 0 additions & 70 deletions
This file was deleted.

features/net/network-socket/WiFiInterface.h

Lines changed: 28 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -39,51 +39,45 @@ class WiFiInterface: public NetworkInterface
3939

4040
/** WiFiInterface lifetime
4141
*/
42-
WiFiInterface();
43-
virtual ~WiFiInterface();
42+
virtual ~WiFiInterface() {};
4443

4544
/** Set the WiFi network credentials
4645
*
47-
* @param ssid Name of the network to connect to
48-
* @param pass Security passphrase to connect to the network
49-
* @param security Type of encryption for connection
50-
* (defaults to NSAPI_SECURITY_NONE)
46+
* @param ssid Name of the network to connect to
47+
* @param pass Security passphrase to connect to the network
48+
* @param security Type of encryption for connection
49+
* (defaults to NSAPI_SECURITY_NONE)
50+
* @return 0 on success, or error code on failure
5151
*/
52-
virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
52+
virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE) = 0;
5353

54-
/** Start the interface
54+
/** Set the WiFi network channel
5555
*
56-
* Attempts to connect to a WiFi network.
57-
*
58-
* @param ssid Name of the network to connect to
59-
* @param pass Security passphrase to connect to the network
60-
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
6156
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
62-
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
6357
* @return 0 on success, or error code on failure
6458
*/
65-
virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE,
66-
uint8_t channel = 0, unsigned timeout = 0) = 0;
59+
virtual int set_channel(uint8_t channel) = 0;
6760

68-
/** Start the interface
61+
/** Gets the current radio signal strength for active connection
6962
*
70-
* Attempts to connect to a WiFi network asynchronously, the call will return straight away. If the @a cb was NULL
71-
* you'll need to query @a get_state until it's in NSAPI_IF_STATE_CONNECTED state, otherwise the @a cb will be
72-
* called with connection results, connected AP details and user data.
63+
* @return Connection strength in dBm (negative value),
64+
* or 0 if measurement impossible
65+
*/
66+
virtual int8_t get_rssi() = 0;
67+
68+
/** Start the interface
7369
*
74-
* Note: @a ssid and @a pass must be kept until the connection is made, that is the callback has been called or the
75-
* state changed to @a NSAPI_IF_STATE_CONNECTED as they are passed by value.
70+
* Attempts to connect to a WiFi network.
7671
*
7772
* @param ssid Name of the network to connect to
7873
* @param pass Security passphrase to connect to the network
79-
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
8074
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
81-
* @param cb Function to be called when the connect finishes (Default: NULL)
82-
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
75+
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
76+
* @return 0 on success, or error code on failure
8377
*/
84-
virtual void connect_async(const char *ssid, const char *pass,nsapi_security_t security = NSAPI_SECURITY_NONE,
85-
uint8_t channel = 0, mbed::Callback<void(nsapi_error_t, wifi_ap_t*)> cb = NULL,
86-
unsigned timeout = 0) = 0;
78+
virtual int connect(const char *ssid, const char *pass,
79+
nsapi_security_t security = NSAPI_SECURITY_NONE,
80+
uint8_t channel = 0);
8781

8882
/** Start the interface
8983
*
@@ -96,51 +90,24 @@ class WiFiInterface: public NetworkInterface
9690

9791
/** Stop the interface
9892
*
99-
* @return 0 on success, or error code on failure
93+
* @return 0 on success, or error code on failure
10094
*/
10195
virtual int disconnect() = 0;
10296

103-
/** Get the current WiFi interface state
104-
*
105-
* @returns Interface state enum
106-
*/
107-
virtual nsapi_if_state_t get_state() = 0;
108-
109-
/** Gets the current radio signal strength for active connection
110-
*
111-
* @return Connection strength in dBm (negative value), or 0 if measurement impossible
112-
*/
113-
virtual int8_t get_rssi() = 0;
114-
11597
/** Scan for available networks
11698
*
117-
* This function will block.
99+
* The scan will
100+
* If the network interface is set to non-blocking mode, scan will attempt to scan
101+
* for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
102+
* is attached, the callback will be called when the operation has completed.
118103
*
119104
* @param ap Pointer to allocated array to store discovered AP
120105
* @param count Size of allocated @a res array, or 0 to only count available AP
121106
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
122107
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
123108
* see @a nsapi_error
124109
*/
125-
virtual int scan(wifi_ap_t *res, unsigned count, unsigned timeout = 0) = 0;
126-
127-
/** Scan for available networks
128-
*
129-
* This function won't block, it'll return immediately and call provided callback for each discovered network with
130-
* AP data and user @a data. After the last discovered network @a cb will be called with NULL as @a ap, so it
131-
* will be always called at least once.
132-
*
133-
* @param cb Function to be called for every discovered network
134-
* @param data User handle that will be passed to @a cb along with the AP data (Default: NULL)
135-
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
136-
*/
137-
virtual void scan_async(mbed::Callback<void(wifi_ap_t*)> cb, unsigned timeout = 0) = 0;
138-
139-
protected:
140-
char *_ssid;
141-
char *_pass;
142-
nsapi_security_t _security;
143-
char _ip_address[16]; //IPv4 only thus 16
110+
virtual int scan(wifi_ap_t *res, unsigned count) = 0;
144111
};
145112

146113
#endif

features/net/network-socket/nsapi_types.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ typedef enum nsapi_error {
4040
NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */
4141
NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */
4242
NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */
43-
NSAPI_ERROR_DNS_FAILURE = -3008, /*!< DNS failed to complete successfully */
44-
NSAPI_ERROR_DHCP_FAILURE = -3009, /*!< DHCP failed to complete successfully */
45-
NSAPI_ERROR_AUTH_FAILURE = -3010, /*!< connection to access point failed */
46-
NSAPI_ERROR_DEVICE_ERROR = -3011, /*!< failure interfacing with the network processor */
47-
NSAPI_ERROR_TIMEOUT = -3012, /*!< operation timed out */
48-
NSAPI_ERROR_NO_SSID = -3013, /*!< ssid not found */
43+
NSAPI_ERROR_NO_SSID = -3008, /*!< ssid not found */
44+
NSAPI_ERROR_DNS_FAILURE = -3009, /*!< DNS failed to complete successfully */
45+
NSAPI_ERROR_DHCP_FAILURE = -3010, /*!< DHCP failed to complete successfully */
46+
NSAPI_ERROR_AUTH_FAILURE = -3011, /*!< connection to access point failed */
47+
NSAPI_ERROR_DEVICE_ERROR = -3012, /*!< failure interfacing with the network processor */
4948
} nsapi_error_t;
5049

5150
/** Enum of encryption types
@@ -62,17 +61,6 @@ typedef enum nsapi_security {
6261
NSAPI_SECURITY_UNSSUPPORTED = 0xFF, /*!< unknown/unsupported security in scan results */
6362
} nsapi_security_t;
6463

65-
/** Enum of interface states
66-
*
67-
* List of all possible states a WiFi network interface can be in
68-
*/
69-
typedef enum nsapi_if_state {
70-
NSAPI_IF_STATE_NOT_CONNECTED = 0x0,
71-
NSAPI_IF_STATE_CONNECTING = 0x01,
72-
NSAPI_IF_STATE_CONNECTED = 0x02,
73-
NSAPI_IF_STATE_ERROR = 0xFF
74-
} nsapi_if_state_t;
75-
7664
/** Maximum size of IP address representation
7765
*/
7866
#define NSAPI_IP_SIZE NSAPI_IPv6_SIZE

0 commit comments

Comments
 (0)