Mistake on this page?
Report an issue in GitHub or email us
WhdSTAInterface.h
1 /* WHD implementation of NetworkInterfaceAPI
2  * Copyright (c) 2017-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef WHD_STA_INTERFACE_H
19 #define WHD_STA_INTERFACE_H
20 
21 #include "netsocket/WiFiInterface.h"
22 #include "netsocket/EMACInterface.h"
23 #include "netsocket/OnboardNetworkStack.h"
24 #include "WhdAccessPoint.h"
25 #include "whd_emac.h"
26 #include "whd_interface.h"
27 #include "whd_types_int.h"
28 
29 struct ol_desc;
30 
31 /** WhdSTAInterface class
32  * Implementation of the NetworkStack for the WHD
33  */
35 public:
36  class OlmInterface {
37  public:
38  /** Get the default OLM interface. */
40 
41  OlmInterface(struct ol_desc *list = NULL) {}
42 
43  virtual int init_ols(void *whd, void *ip)
44  {
45  return 0;
46  }
47  virtual int sleep()
48  {
49  return 0;
50  }
51  virtual int wake()
52  {
53  return 0;
54  }
55 
56  virtual void deinit_ols(void) {}
57  };
58 
60  WHD_EMAC &emac = WHD_EMAC::get_instance(),
63  whd_interface_shared_info_t &shared = whd_iface_shared);
64 
66 
67  /* Turn on the wifi device*/
68  void wifi_on();
69 
70  /** Start the interface
71  *
72  * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
73  * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
74  *
75  * @return 0 on success, negative error code on failure
76  */
78 
79  /** Start the interface
80  *
81  * Attempts to connect to a WiFi network.
82  *
83  * @param ssid Name of the network to connect to
84  * @param pass Security passphrase to connect to the network
85  * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
86  * @param channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED
87  * @return 0 on success, or error code on failure
88  */
89  nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0);
90 
91  /** Stop the interface
92  * @return 0 on success, negative on failure
93  */
95 
96  /** Set the WiFi network credentials
97  *
98  * @param ssid Name of the network to connect to
99  * @param pass Security passphrase to connect to the network
100  * @param security Type of encryption for connection
101  * (defaults to NSAPI_SECURITY_NONE)
102  * @return 0 on success, or error code on failure
103  */
104  nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
105 
106  /** Set the WiFi network channel - NOT SUPPORTED
107  *
108  * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED
109  *
110  * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
111  * @return Not supported, returns NSAPI_ERROR_UNSUPPORTED
112  */
113  nsapi_error_t set_channel(uint8_t channel)
114  {
115  if (channel != 0) {
117  }
118 
119  return 0;
120  }
121 
122  /** Set blocking status of interface.
123  * Nonblocking mode unsupported.
124  *
125  * @param blocking true if connect is blocking
126  * @return 0 on success, negative error code on failure
127  */
129  {
130  if (blocking) {
131  _blocking = blocking;
132  return NSAPI_ERROR_OK;
133  } else {
135  }
136  }
137 
138  /** Gets the current radio signal strength for active connection
139  *
140  * @return Connection strength in dBm (negative value)
141  */
142  int8_t get_rssi();
143 
144  /** Scan for available networks in WiFiAccessPoint format
145  *
146  * This function will block.
147  *
148  * @param ap Pointer to allocated array of WiFiAccessPoint format for discovered AP
149  * @param count Size of allocated @a res array, or 0 to only count available AP
150  * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
151  * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
152  * see @a nsapi_error
153  */
154  int scan(WiFiAccessPoint *res, unsigned count);
155 
156  /** Scan for available networks in WhdAccessPoint format
157  *
158  * This function will block.
159  *
160  * @param ap Pointer to allocated array of WhdAccessPoint format for discovered AP
161  * @param count Size of allocated @a res array, or 0 to only count available AP
162  * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
163  * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
164  * see @a nsapi_error
165  */
166  int scan_whd(WhdAccessPoint *res, unsigned count);
167 
168  /* is interface connected, if yes return WICED_SUCCESS else WICED_NOT_CONNECTED */
169  int is_interface_connected();
170 
171  /* get bssid of the AP if success return WICED_SUCCESS else WICED_ERROR */
172  int get_bssid(uint8_t *bssid);
173 
174  /* print WHD log (this routine will malloc/free a buffer
175  * You need to enable printing with WHD_LOGGING_BUFFER_ENABLE
176  */
177  int whd_log_print(void);
178 
179  /* read WHD log */
180  int whd_log_read(char *buffer, int buffer_size);
181 
182  /* Get EDCF AC params */
183  nsapi_error_t wifi_get_ac_params_sta(void *ac_param);
184 
185  /* get iovar value */
186  int wifi_get_iovar_value(const char *iovar, uint32_t *value);
187 
188  /* set iovar value */
189  int wifi_set_iovar_value(const char *iovar, uint32_t value);
190 
191  /* set ioctl value */
192  int wifi_set_ioctl_value(uint32_t ioctl, uint32_t value) ;
193 
194  /* get ioctl value */
195  int wifi_get_ioctl_value(uint32_t ioctl, uint32_t *value);
196 
197  /* get ioctl buffer */
198  int wifi_get_ioctl_buffer(uint32_t ioctl, uint8_t *buffer, uint16_t len);
199 
200  /* set ioctl buffer */
201  int wifi_set_ioctl_buffer(uint32_t ioctl, uint8_t *buffer, uint16_t len);
202 
203  /* get WHD ifp value */
204  int wifi_get_ifp(whd_interface_t *ifp);
205 
206  /* set wifi interface up */
207  int wifi_set_up(void);
208 
209  /* set wifi interface down */
210  int wifi_set_down(void);
211 
212  /* set wifi coex configuration */
213  int wifi_set_coex_config(whd_coex_config_t *coex_config);
214 
215  /** Set Offload Manager Information
216  * NOTE: Only allowed while disconnected
217  *
218  * @param olm Offload Manager info structure
219  * @return true if completed successfully
220  * false if Interface is connected
221  */
223  {
225  _olm = olm;
226  return true;
227  }
228  return false;
229  }
230 
231  /** Network stack is suspended
232  *
233  * @return 0 if successful
234  */
236  {
237  int ret = _olm->sleep();
238  return ret;
239  }
240 
241  /** Network stack is resuming
242  *
243  * @return 0 if successful
244  */
246  {
247  int ret = _olm->wake();
248  return ret;
249  }
250 
251 protected:
252  int internal_scan(WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type);
253 
254 private:
255  char _ssid[33]; /* The longest possible name (defined in 802.11) +1 for the \0 */
256  char _pass[64]; /* The longest allowed passphrase + 1 */
257  nsapi_security_t _security;
258  WHD_EMAC &_whd_emac;
259  OlmInterface *_olm;
260  whd_interface_shared_info_t &_iface_shared;
261 };
262 
263 #endif
Common interface between Wi-Fi devices.
Definition: WiFiInterface.h:31
EMACInterface class Implementation of the NetworkInterface for an EMAC-based driver.
Definition: EMACInterface.h:38
int scan(WiFiAccessPoint *res, unsigned count)
Scan for available networks in WiFiAccessPoint format.
WhdSTAInterface class Implementation of the NetworkStack for the WHD.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
int8_t get_rssi()
Gets the current radio signal strength for active connection.
mbed OS API for onboard IP stack abstraction
int set_olm(OlmInterface *olm)
Set Offload Manager Information NOTE: Only allowed while disconnected.
int net_suspended()
Network stack is suspended.
nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security=NSAPI_SECURITY_NONE)
Set the WiFi network credentials.
WhdAccessPoint class.
nsapi_connection_status_t get_connection_status() const override
Get the connection status.
nsapi_error_t set_channel(uint8_t channel)
Set the WiFi network channel - NOT SUPPORTED.
nsapi_error_t disconnect()
Stop the interface.
Connected isochronous stream linked list.
Definition: lctr_int_cis.h:306
enum nsapi_security nsapi_security_t
Enum of encryption types.
int net_resuming()
Network stack is resuming.
static OnboardNetworkStack & get_default_instance()
Return the default on-board network stack.
nsapi_error_t set_blocking(bool blocking)
Set blocking status of interface.
static OlmInterface & get_default_instance()
Get the default OLM interface.
nsapi_error_t connect()
Start the interface.
int scan_whd(WhdAccessPoint *res, unsigned count)
Scan for available networks in WhdAccessPoint format.
WiFiAccessPoint class.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.