Mistake on this page?
Report an issue in GitHub or email us
EMW3080BInterface.h
1 /* EMW3080B implementation of NetworkInterfaceAPI
2  * Copyright (c) STMicroelectronics 2021
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 EMW3080B_INTERFACE_H
19 #define EMW3080B_INTERFACE_H
20 
21 #if defined(MBED_CONF_NSAPI_PRESENT)
22 
23 #include <inttypes.h>
24 
25 #include "mbed.h"
26 #include "mbed_debug.h"
27 #include "mx_wifi.h"
28 #include "netsocket/WiFiInterface.h"
29 #include "netsocket/EMACInterface.h"
30 #include "netsocket/OnboardNetworkStack.h"
31 #include "EMW3080B_EMAC.h"
32 
33 
34 /** EMW3080BInterface class
35  * Implementation of the NetworkStack for the EMW3080B
36  */
37 class EMW3080BInterface : public WiFiInterface, public EMACInterface {
38 public:
39  EMW3080BInterface(bool debug = MBED_CONF_EMW3080B_WIFI_DEBUG,
40  PinName mosi = MBED_CONF_EMW3080B_WIFI_MOSI,
41  PinName miso = MBED_CONF_EMW3080B_WIFI_MISO,
42  PinName sclk = MBED_CONF_EMW3080B_WIFI_SCLK,
43  PinName nss = MBED_CONF_EMW3080B_WIFI_NSS,
44  PinName notify = MBED_CONF_EMW3080B_WIFI_NOTIFY,
45  PinName flow = MBED_CONF_EMW3080B_WIFI_FLOW,
46  PinName reset = MBED_CONF_EMW3080B_WIFI_RESET,
47  PinName tx = MBED_CONF_EMW3080B_WIFI_TX,
48  PinName rx = MBED_CONF_EMW3080B_WIFI_RX,
49  EMAC &emac = EMW3080B_EMAC::get_instance(),
51  );
52 
53  /** Start the interface
54  *
55  * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
56  * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
57  *
58  * @return 0 on success, negative error code on failure
59  */
61 
62  /** Start the interface
63  *
64  * Attempts to connect to a WiFi network.
65  *
66  * @param ssid Name of the network to connect to
67  * @param pass Security passphrase to connect to the network
68  * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
69  * @param channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED
70  * @return 0 on success, or error code on failure
71  */
72  nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0);
73 
74  /** Stop the interface
75  * @return 0 on success, negative on failure
76  */
78 
79  /** Set the WiFi network credentials
80  *
81  * @param ssid Name of the network to connect to
82  * @param pass Security passphrase to connect to the network
83  * @param security Type of encryption for connection
84  * (defaults to NSAPI_SECURITY_NONE)
85  * @return 0 on success, or error code on failure
86  */
87  nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
88 
89  /** Set the WiFi network channel - NOT SUPPORTED
90  *
91  * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED
92  *
93  * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
94  * @return Not supported, returns NSAPI_ERROR_UNSUPPORTED
95  */
96  nsapi_error_t set_channel(uint8_t channel)
97  {
98  if (channel != 0) {
100  }
101 
102  return 0;
103  }
104 
105  /** Gets the current radio signal strength for active connection
106  *
107  * @return Connection strength in dBm (negative value)
108  */
109  int8_t get_rssi();
110 
111  /** Scan for available networks
112  *
113  * This function will block.
114  *
115  * @param ap Pointer to allocated array to store discovered AP
116  * @param count Size of allocated @a res array, or 0 to only count available AP
117  * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
118  * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
119  * see @a nsapi_error
120  */
121  int scan(WiFiAccessPoint *res, unsigned count);
122 
123  MX_WIFIObject_t MxWifiObj;
124 
125 private:
126 
127  nsapi_security_t emw_sec2nsapi_sec(mwifi_security_t sec)
128  {
129  nsapi_security_t sec_out;
130 
131  switch (sec) {
132  case MX_WIFI_SEC_NONE:
133  sec_out = NSAPI_SECURITY_NONE;
134  break;
135  case MX_WIFI_SEC_WEP:
136  sec_out = NSAPI_SECURITY_WEP;
137  break;
138  case MX_WIFI_SEC_WPA_AES:
140  sec_out = NSAPI_SECURITY_WPA;
141  break;
145  sec_out = NSAPI_SECURITY_WPA2;
146  break;
147  case MX_WIFI_SEC_AUTO:
148  sec_out = NSAPI_SECURITY_WPA_WPA2;
149  break;
150  default:
151  sec_out = NSAPI_SECURITY_WPA_WPA2;
152  break;
153 
154  }
155  return sec_out;
156  }
157 
158  MX_WIFI_SecurityType_t nsapi_sec2emw_sec(nsapi_security_t sec)
159  {
160  MX_WIFI_SecurityType_t mx_sec;
161 
162  switch (sec) {
163  case NSAPI_SECURITY_NONE:
164  mx_sec = MX_WIFI_SEC_NONE;
165  break;
166  case NSAPI_SECURITY_WEP:
167  mx_sec = MX_WIFI_SEC_WEP;
168  break;
169  case NSAPI_SECURITY_WPA:
170  mx_sec = MX_WIFI_SEC_WPA_AES;
171  break;
172  case NSAPI_SECURITY_WPA2:
173  mx_sec = MX_WIFI_SEC_WPA2_AES;
174  break;
175  default:
176  mx_sec = MX_WIFI_SEC_AUTO;
177  break;
178  }
179 
180  return mx_sec;
181  }
182 
183  /* MXCHIP array size for SCAN is 2KB , so limits number of AP to 20 */
184 #define MAX_AP_COUNT 20
185 
186 
187  int8_t IO_Init(uint16_t mode);
188  int8_t IO_DeInit(void);
189  void IO_Delay(uint32_t delayms);
190  uint16_t IO_Send(uint8_t *data, uint16_t len);
191  uint16_t IO_Receive(uint8_t *buffer, uint16_t buff_size);
192 
193  void probe(void);
194  void release(void);
195  char _ssid[33]; /* The longest possible name (defined in 802.11) +1 for the \0 */
196  char _pass[64]; /* The longest allowed passphrase + 1 */
197  mwifi_ap_info_t _ap_info[MAX_AP_COUNT];
199  volatile bool _isConnected;
200  Mutex _mutex;
201 
202  uint8_t _debug_level;
203 };
204 
205 #endif /* MBED_CONF_NSAPI_PRESENT */
206 
207 #endif /* EMW3080B_INTERFACE_H */
WPA /w TKIP.
Definition: mx_wifi.h:162
Common interface between Wi-Fi devices.
Definition: WiFiInterface.h:32
uint8_t mwifi_security_t
Wi-Fi softAP info.
Definition: mx_wifi.h:683
Wired Equivalent Privacy.
Definition: mx_wifi.h:161
MX_WIFI_SecurityType_t
Security settings for wifi network.
Definition: mx_wifi.h:158
nsapi_error_t disconnect() override
Disconnect from the network.
virtual nsapi_error_t set_channel(uint8_t channel)=0
Set the Wi-Fi network channel.
EMACInterface class Implementation of the NetworkInterface for an EMAC-based driver.
Definition: EMACInterface.h:39
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:142
nsapi_error_t connect() override
Connect to a network.
virtual nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security=NSAPI_SECURITY_NONE)=0
Set the Wi-Fi network credentials.
WPA2 /w AES.
Definition: mx_wifi.h:165
mbed OS API for onboard IP stack abstraction
virtual int8_t get_rssi()=0
Get the current radio signal strength for active connection.
Header for mx_wifi.c module.
Open system.
Definition: mx_wifi.h:160
WPA2 /w TKIP.
Definition: mx_wifi.h:164
WPA /w AES.
Definition: mx_wifi.h:163
It is used when calling mwifi_connect, MXOS read security type from scan result.
Definition: mx_wifi.h:167
virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, nsapi_size_t count)=0
Scan for available networks.
Wi-Fi Wi-Fi object handle.
Definition: mx_wifi.h:294
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: EMAC.h:33
enum nsapi_security nsapi_security_t
Enum of encryption types.
static void debug(const char *format,...) MBED_PRINTF(1
Output a debug message.
Definition: mbed_debug.h:44
static OnboardNetworkStack & get_default_instance()
Return the default on-board network stack.
WiFiAccessPoint class.
WPA2 /w AES or TKIP.
Definition: mx_wifi.h:166
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.