From 0f40c121d52a254455096d4a831e8045b1e7956e Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 30 Sep 2016 15:54:13 -0500 Subject: [PATCH] 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. --- .../net/network-socket/WiFiAccessPoint.cpp | 37 ++++++++++ features/net/network-socket/WiFiAccessPoint.h | 70 +++++++++++++++++++ features/net/network-socket/WiFiInterface.h | 12 +--- features/net/network-socket/nsapi.h | 1 + features/net/network-socket/nsapi_types.h | 12 ++++ 5 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 features/net/network-socket/WiFiAccessPoint.cpp create mode 100644 features/net/network-socket/WiFiAccessPoint.h diff --git a/features/net/network-socket/WiFiAccessPoint.cpp b/features/net/network-socket/WiFiAccessPoint.cpp new file mode 100644 index 0000000000..f7a5932550 --- /dev/null +++ b/features/net/network-socket/WiFiAccessPoint.cpp @@ -0,0 +1,37 @@ +#include "network-socket/WiFiAccessPoint.h" + +WiFiAccessPoint::WiFiAccessPoint() +{ + memset(&_ap, 0, sizeof(_ap)); +} + +WiFiAccessPoint::WiFiAccessPoint(nsapi_wifi_ap_t ap) +{ + _ap = ap; +} + +const char *WiFiAccessPoint::get_ssid() const +{ + return _ap.ssid; +} + +const uint8_t *WiFiAccessPoint::get_bssid() const +{ + return _ap.bssid; +} + +nsapi_security_t WiFiAccessPoint::get_security() const +{ + return _ap.security; +} + +int8_t WiFiAccessPoint::get_rssi() const +{ + return _ap.rssi; +} + +uint8_t WiFiAccessPoint::get_channel() const +{ + return _ap.channel; +} + diff --git a/features/net/network-socket/WiFiAccessPoint.h b/features/net/network-socket/WiFiAccessPoint.h new file mode 100644 index 0000000000..a8c90bf6e1 --- /dev/null +++ b/features/net/network-socket/WiFiAccessPoint.h @@ -0,0 +1,70 @@ +/* WiFiInterface + * Copyright (c) 2015 - 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WIFI_ACCESS_POINT_H +#define WIFI_ACCESS_POINT_H + +#include +#include "network-socket/nsapi_types.h" + +/** WiFiAccessPoint class + * + * Class that represents a WiFi Access Point + * Common interface that is shared between WiFi devices + */ +class WiFiAccessPoint +{ + /** WiFiAccessPoint lifetime + */ + WiFiAccessPoint(); + WiFiAccessPoint(nsapi_wifi_ap_t ap); + + /** Get an access point's ssid + * + * @return The ssid of the access point + */ + const char *get_ssid() const; + + /** Get an access point's bssid + * + * @return The bssid of the access point + */ + const uint8_t *get_bssid() const; + + /** Get an access point's security + * + * @return The security type of the access point + */ + nsapi_security_t get_security() const; + + /** Gets the radio signal strength for the access point + * + * @return Connection strength in dBm (negative value), + * or 0 if measurement impossible + */ + int8_t get_rssi() const; + + /** Get the access point's channel + * + * @return The channel of the access point + */ + uint8_t get_channel() const; + +private: + nsapi_wifi_ap_t _ap; +}; + +#endif diff --git a/features/net/network-socket/WiFiInterface.h b/features/net/network-socket/WiFiInterface.h index f997e63a60..3169da7daf 100644 --- a/features/net/network-socket/WiFiInterface.h +++ b/features/net/network-socket/WiFiInterface.h @@ -20,7 +20,7 @@ #include #include "Callback.h" #include "network-socket/NetworkInterface.h" -#include "nsapi.h" +#include "network-socket/WiFiAccessPoint.h" /** WiFiInterface class * @@ -29,14 +29,6 @@ class WiFiInterface: public NetworkInterface { public: - typedef struct wifi_ap { - char ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */ - uint8_t bssid[6]; - nsapi_security_t security; - int8_t rssi; - uint8_t channel; - } wifi_ap_t; - /** WiFiInterface lifetime */ virtual ~WiFiInterface() {}; @@ -107,7 +99,7 @@ public: * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error * see @a nsapi_error */ - virtual int scan(wifi_ap_t *res, unsigned count) = 0; + virtual int scan(WiFiAccessPoint *res, unsigned count) = 0; }; #endif diff --git a/features/net/network-socket/nsapi.h b/features/net/network-socket/nsapi.h index d61fb5502c..b5af7c3144 100644 --- a/features/net/network-socket/nsapi.h +++ b/features/net/network-socket/nsapi.h @@ -25,6 +25,7 @@ // entry point for C++ api #include "network-socket/SocketAddress.h" +#include "network-socket/WiFiAccessPoint.h" #include "network-socket/NetworkStack.h" #include "network-socket/NetworkInterface.h" diff --git a/features/net/network-socket/nsapi_types.h b/features/net/network-socket/nsapi_types.h index 0efca8bea5..6607199df9 100644 --- a/features/net/network-socket/nsapi_types.h +++ b/features/net/network-socket/nsapi_types.h @@ -163,6 +163,18 @@ typedef enum nsapi_option { NSAPI_RCVBUF, /*!< Sets recv buffer size */ } nsapi_option_t; +/** nsapi_wifi_ap structure + * + * Structure representing a WiFi Access Point + */ +typedef struct nsapi_wifi_ap { + char ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */ + uint8_t bssid[6]; + nsapi_security_t security; + int8_t rssi; + uint8_t channel; +} nsapi_wifi_ap_t; + /** nsapi_stack structure *