|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
| 18 | +#include <lib/support/BytesToHex.h> |
18 | 19 | #include <lib/support/CodeUtils.h>
|
19 | 20 | #include <platform/CHIPDeviceLayer.h>
|
20 | 21 | #include <platform/Darwin/ConfigurationManagerImpl.h>
|
@@ -72,18 +73,23 @@ bool Next(WiFiScanResponse & scanResponse) override
|
72 | 73 | void CopyNetworkInformationTo(WiFiScanResponse & destination, CWNetwork * source)
|
73 | 74 | {
|
74 | 75 | destination.security = GetWiFiSecurity(source);
|
75 |
| - destination.ssidLen = [source.ssid length]; |
76 |
| - destination.channel = source.wlanChannel.channelNumber; |
| 76 | + destination.channel = static_cast<uint16_t>(source.wlanChannel.channelNumber); |
77 | 77 | destination.wiFiBand = GetWiFiBand(source.wlanChannel);
|
78 |
| - destination.rssi = source.rssiValue; |
79 |
| - CopyStringTo(destination.ssid, source.ssid, DeviceLayer::Internal::kMaxWiFiSSIDLength); |
80 |
| - CopyStringTo(destination.bssid, source.bssid, DeviceLayer::Internal::kWiFiBSSIDLength); |
81 |
| - } |
82 |
| - |
83 |
| - void CopyStringTo(uint8_t * destination, NSString * source, size_t maxLength) |
84 |
| - { |
85 |
| - NSData * data = [source dataUsingEncoding:NSUTF8StringEncoding]; |
86 |
| - memcpy(destination, [data bytes], std::min([data length], maxLength)); |
| 78 | + destination.rssi = static_cast<int8_t>(source.rssiValue); |
| 79 | + |
| 80 | + NSData * ssidData = source.ssidData; |
| 81 | + destination.ssidLen = static_cast<uint8_t>(std::min(ssidData.length, DeviceLayer::Internal::kMaxWiFiSSIDLength)); |
| 82 | + memcpy(destination.ssid, ssidData.bytes, destination.ssidLen); |
| 83 | + |
| 84 | + // source.bssid looks like "00:00:00:00:00:00" if it's not nil. |
| 85 | + NSString * bssid = source.bssid; |
| 86 | + // 3 chars per byte, except the last byte. |
| 87 | + if (bssid.length == 3 * sizeof(destination.bssid) - 1) { |
| 88 | + const char * chars = bssid.UTF8String; |
| 89 | + for (size_t i = 0; i < sizeof(destination.bssid); ++i) { |
| 90 | + Encoding::HexToBytes(&chars[3 * i], 2, &destination.bssid[i], 1); |
| 91 | + } |
| 92 | + } |
87 | 93 | }
|
88 | 94 |
|
89 | 95 | WiFiSecurity GetWiFiSecurity(CWNetwork * network)
|
|
0 commit comments