Skip to content

Commit 0f40c12

Browse files
committed
wifi - Moved wifi_ap_t into its own class WiFiAccessPoint
Using a class for this structure is more idiomatic C++, allows future deprecations, and more flexibility of the internal structure. Additionally, this matches to design of the SocketAddress class specific to the network-socket api.
1 parent 5b12539 commit 0f40c12

File tree

5 files changed

+122
-10
lines changed

5 files changed

+122
-10
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "network-socket/WiFiAccessPoint.h"
2+
3+
WiFiAccessPoint::WiFiAccessPoint()
4+
{
5+
memset(&_ap, 0, sizeof(_ap));
6+
}
7+
8+
WiFiAccessPoint::WiFiAccessPoint(nsapi_wifi_ap_t ap)
9+
{
10+
_ap = ap;
11+
}
12+
13+
const char *WiFiAccessPoint::get_ssid() const
14+
{
15+
return _ap.ssid;
16+
}
17+
18+
const uint8_t *WiFiAccessPoint::get_bssid() const
19+
{
20+
return _ap.bssid;
21+
}
22+
23+
nsapi_security_t WiFiAccessPoint::get_security() const
24+
{
25+
return _ap.security;
26+
}
27+
28+
int8_t WiFiAccessPoint::get_rssi() const
29+
{
30+
return _ap.rssi;
31+
}
32+
33+
uint8_t WiFiAccessPoint::get_channel() const
34+
{
35+
return _ap.channel;
36+
}
37+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* WiFiInterface
2+
* Copyright (c) 2015 - 2016 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef WIFI_ACCESS_POINT_H
18+
#define WIFI_ACCESS_POINT_H
19+
20+
#include <string.h>
21+
#include "network-socket/nsapi_types.h"
22+
23+
/** WiFiAccessPoint class
24+
*
25+
* Class that represents a WiFi Access Point
26+
* Common interface that is shared between WiFi devices
27+
*/
28+
class WiFiAccessPoint
29+
{
30+
/** WiFiAccessPoint lifetime
31+
*/
32+
WiFiAccessPoint();
33+
WiFiAccessPoint(nsapi_wifi_ap_t ap);
34+
35+
/** Get an access point's ssid
36+
*
37+
* @return The ssid of the access point
38+
*/
39+
const char *get_ssid() const;
40+
41+
/** Get an access point's bssid
42+
*
43+
* @return The bssid of the access point
44+
*/
45+
const uint8_t *get_bssid() const;
46+
47+
/** Get an access point's security
48+
*
49+
* @return The security type of the access point
50+
*/
51+
nsapi_security_t get_security() const;
52+
53+
/** Gets the radio signal strength for the access point
54+
*
55+
* @return Connection strength in dBm (negative value),
56+
* or 0 if measurement impossible
57+
*/
58+
int8_t get_rssi() const;
59+
60+
/** Get the access point's channel
61+
*
62+
* @return The channel of the access point
63+
*/
64+
uint8_t get_channel() const;
65+
66+
private:
67+
nsapi_wifi_ap_t _ap;
68+
};
69+
70+
#endif

features/net/network-socket/WiFiInterface.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <string.h>
2121
#include "Callback.h"
2222
#include "network-socket/NetworkInterface.h"
23-
#include "nsapi.h"
23+
#include "network-socket/WiFiAccessPoint.h"
2424

2525
/** WiFiInterface class
2626
*
@@ -29,14 +29,6 @@
2929
class WiFiInterface: public NetworkInterface
3030
{
3131
public:
32-
typedef struct wifi_ap {
33-
char ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
34-
uint8_t bssid[6];
35-
nsapi_security_t security;
36-
int8_t rssi;
37-
uint8_t channel;
38-
} wifi_ap_t;
39-
4032
/** WiFiInterface lifetime
4133
*/
4234
virtual ~WiFiInterface() {};
@@ -107,7 +99,7 @@ class WiFiInterface: public NetworkInterface
10799
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
108100
* see @a nsapi_error
109101
*/
110-
virtual int scan(wifi_ap_t *res, unsigned count) = 0;
102+
virtual int scan(WiFiAccessPoint *res, unsigned count) = 0;
111103
};
112104

113105
#endif

features/net/network-socket/nsapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
// entry point for C++ api
2727
#include "network-socket/SocketAddress.h"
28+
#include "network-socket/WiFiAccessPoint.h"
2829
#include "network-socket/NetworkStack.h"
2930

3031
#include "network-socket/NetworkInterface.h"

features/net/network-socket/nsapi_types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ typedef enum nsapi_option {
163163
NSAPI_RCVBUF, /*!< Sets recv buffer size */
164164
} nsapi_option_t;
165165

166+
/** nsapi_wifi_ap structure
167+
*
168+
* Structure representing a WiFi Access Point
169+
*/
170+
typedef struct nsapi_wifi_ap {
171+
char ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
172+
uint8_t bssid[6];
173+
nsapi_security_t security;
174+
int8_t rssi;
175+
uint8_t channel;
176+
} nsapi_wifi_ap_t;
177+
166178

167179
/** nsapi_stack structure
168180
*

0 commit comments

Comments
 (0)