Mistake on this page?
Report an issue in GitHub or email us
SclSTAInterface.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2020 Cypress Semiconductor Corporation
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 SCL_STA_INTERFACE_H
19 #define SCL_STA_INTERFACE_H
20 
21 
22 /** @file
23  * Provides SCL interface functions to be used with WiFiInterface or NetworkInterface Objects
24  */
25 
26 #include "netsocket/WiFiInterface.h"
27 #include "netsocket/EMACInterface.h"
28 #include "netsocket/OnboardNetworkStack.h"
29 #include "scl_emac.h"
30 #include "scl_wifi_api.h"
31 #include "scl_types.h"
32 #include "SclAccessPoint.h"
33 #include "scl_interface.h"
34 #define MAX_SSID_LENGTH (33) /**< Maximum ssid length */
35 #define MAX_PASSWORD_LENGTH (64) /**< Maximum password length */
36 
37 /** SclSTAInterface class
38  * Implementation of the Network Stack for the SCL
39  */
41 public:
42 
46  scl_interface_shared_info_t &shared = scl_iface_shared);
47 
48  /** Gets the current instance of the SclSTAInterface
49  *
50  * @return Pointer to the object of class SclSTAInterface.
51  */
53 
54  /** Turns on the Wi-Fi device
55  *
56  * @return void
57  */
58  void wifi_on();
59 
60  /** Starts the interface
61  *
62  * Attempts to connect to a Wi-Fi network. Requires ssid and passphrase to be set.
63  * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
64  *
65  * @return 0 on success, negative error code on failure.
66  */
68 
69  /** Starts the interface
70  *
71  * Attempts to connect to a Wi-Fi network.
72  *
73  * @param ssid Name of the network to connect to.
74  * @param pass Security passphrase to connect to the network.
75  * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE).
76  * @param channel This parameter is not supported, setting it to a value other than 0 will result in NSAPI_ERROR_UNSUPPORTED.
77  * @return 0 on success, negative error code on failure.
78  */
79  nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0);
80 
81  /** Disconnects the interface
82  *
83  * @return 0 on success, negative error code on failure.
84  */
86 
87  /** Set the Wi-Fi network credentials
88  *
89  * @param ssid Name of the network to connect to.
90  * @param pass Security passphrase to connect to the network.
91  * @param security Type of encryption for connection.
92  * (defaults to NSAPI_SECURITY_NONE)
93  * @return 0 on success, negative error code on failure.
94  */
95  nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
96 
97  /** Sets the Wi-Fi network channel - NOT SUPPORTED
98  *
99  * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED.
100  *
101  * @param channel Channel on which the connection is to be made (Default: 0).
102  * @return Not supported, returns NSAPI_ERROR_UNSUPPORTED.
103  */
104  nsapi_error_t set_channel(uint8_t channel)
105  {
106  if (channel != 0) {
108  }
109  return 0;
110  }
111 
112  /** Set blocking status of interface.
113  * Nonblocking mode is not supported.
114  *
115  * @param blocking True if connect is blocking
116  * @return 0 on success, negative error code on failure
117  */
119  {
120  if (blocking) {
121  _blocking = blocking;
122  return NSAPI_ERROR_OK;
123  } else {
125  }
126  }
127  /** Gets the current radio signal strength for active connection
128  *
129  * @return Connection strength in dBm (negative value).
130  */
131  int8_t get_rssi();
132 
133  /** Scan for available networks in WiFiAccessPoint format
134  *
135  * This function will block.
136  *
137  * @param aps Pointer to allocated array of WiFiAccessPoint format for discovered AP
138  * @param count Size of allocated @a res array, or 0 to only count available AP
139  * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
140  * see @a nsapi_error
141  */
142  int scan(WiFiAccessPoint *aps, unsigned count);
143 
144  /** This function is used to indicate if the device is connected to the network.
145  *
146  * @return SCL_SUCCESS if device is connected.
147  */
149 
150  /** Gets the BSSID (MAC address of device connected to).
151  *
152  * @param bssid Pointer to the BSSID value.
153  * @return SCL_SUCCESS if BSSID is obtained successfully.
154  * @return SCL_BADARG if input parameter is NULL.
155  * @return SCL_ERROR if unable to fetch BSSID.
156  */
157  int get_bssid(uint8_t *bssid);
158 
159  /** This function is used to set up the Wi-Fi interface.
160  * This function should be used after the wifi_on.
161  *
162  * @return SCL_SUCCESS if the Wi-Fi interface is set up successfully.
163  */
164  int wifi_set_up(void);
165 protected:
166  int internal_scan(WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type);
167 
168 private:
169 
170  char _ssid[MAX_SSID_LENGTH]; /**< The longest possible name (defined in 802.11) +1 for the \0 */
171  char _pass[MAX_PASSWORD_LENGTH]; /**< The longest allowed passphrase + 1 */
172  nsapi_security_t _security; /**< Security type */
173  SCL_EMAC &_scl_emac; /**< SCL_EMAC object */
174  scl_interface_shared_info_t &_iface_shared;
175 };
176 #endif /* ifndef SCL_STA_INTERFACE_H */
Common interface between Wi-Fi devices.
Definition: WiFiInterface.h:32
int is_interface_connected()
This function is used to indicate if the device is connected to the network.
static SCL_EMAC & get_instance()
Get the EMAC instance.
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:140
int8_t get_rssi()
Gets the current radio signal strength for active connection.
int get_bssid(uint8_t *bssid)
Gets the BSSID (MAC address of device connected to).
SclSTAInterface class Implementation of the Network Stack for the SCL.
nsapi_error_t set_blocking(bool blocking)
Set blocking status of interface.
mbed OS API for onboard IP stack abstraction
nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security=NSAPI_SECURITY_NONE)
Set the Wi-Fi network credentials.
void wifi_on()
Turns on the Wi-Fi device.
int scan(WiFiAccessPoint *aps, unsigned count)
Scan for available networks in WiFiAccessPoint format.
int wifi_set_up(void)
This function is used to set up the Wi-Fi interface.
static SclSTAInterface * get_default_instance()
Gets the current instance of the SclSTAInterface.
nsapi_error_t set_channel(uint8_t channel)
Sets the Wi-Fi network channel - NOT SUPPORTED.
#define MAX_SSID_LENGTH
Maximum ssid length.
enum nsapi_security nsapi_security_t
Enum of encryption types.
static OnboardNetworkStack & get_default_instance()
Return the default on-board network stack.
nsapi_error_t connect()
Starts the interface.
Provides EMAC interface functions to be used with the SCL_EMAC object.
nsapi_error_t disconnect()
Disconnects the interface.
WiFiAccessPoint class.
#define MAX_PASSWORD_LENGTH
Maximum password length.
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.