Skip to content

Commit 500b326

Browse files
authored
Add and Leverage 'WirelessSignalType' and 'WirelessSignal' Enumeration and Aggregate Type (project-chip#42732)
* Add 'WirelessSignalType' wireless signal strength assessment or measurement type. * Add 'WirelessSignal' wireless signal type and strength assessment. * Replace 'int8_t rssi' with 'WirelessSignal signal'. This allows encoding not only the current type of quantitative dBm-style wireless signal measurements but also a qualitative, 0-100 wireless signal assessment. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the test RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type. * Update RSSI assignment to reflect 'WirelessSignal'. This updates the RSSI assignment to reflect the newly-introduced 'WirelessSignal' wireless signal type and strength assessment type.
1 parent 2b1029e commit 500b326

23 files changed

Lines changed: 160 additions & 102 deletions

src/app/clusters/network-commissioning/WifiScanResponse.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ CHIP_ERROR WifiScanResponseToTLV::EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag
5656
result.bssid = ByteSpan(scanResponse.bssid, sizeof(scanResponse.bssid));
5757
result.channel = scanResponse.channel;
5858
result.wiFiBand = scanResponse.wiFiBand;
59-
result.rssi = scanResponse.rssi;
59+
if (scanResponse.signal.type == DeviceLayer::NetworkCommissioning::WirelessSignalType::kdBm)
60+
result.rssi = scanResponse.signal.strength;
61+
else
62+
result.rssi = 0;
6063
ReturnErrorOnFailure(DataModel::Encode(writer, TLV::AnonymousTag(), result));
6164

6265
++networksEncoded;

src/app/clusters/network-commissioning/tests/TestWifiResponse.cpp

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,28 @@ TEST_F(TestWifiResponseEncoding, TestErrorEncode)
8989

9090
TEST_F(TestWifiResponseEncoding, TestSuccessEncode)
9191
{
92-
TestResponseIterator<3> fakeResponses{ WiFiScanResponse{
93-
.security = BitFlags<WiFiSecurityBitmap>(WiFiSecurityBitmap::kWpa2Personal),
94-
.ssid = { 'f', 'o', 'o', 0 },
95-
.ssidLen = 3,
96-
.bssid = { '1', '2', '3', '4', 0 },
97-
.channel = 123,
98-
.wiFiBand = WiFiBandEnum::k5g,
99-
.rssi = 10,
100-
},
101-
WiFiScanResponse{
102-
.security = BitFlags<WiFiSecurityBitmap>(WiFiSecurityBitmap::kWpa2Personal),
103-
.ssid = { 'b', 'a', 'r', 0 },
104-
.ssidLen = 3,
105-
.bssid = { 'x', 'y', 'z', 0 },
106-
.channel = 321,
107-
.wiFiBand = WiFiBandEnum::k2g4,
108-
.rssi = 20,
109-
},
110-
WiFiScanResponse{
111-
.security = BitFlags<WiFiSecurityBitmap>(WiFiSecurityBitmap::kWpa2Personal),
112-
.ssid = { 'b', 'a', 0 },
113-
.ssidLen = 2,
114-
.bssid = { 'z', 'z', 'z', 0 },
115-
.channel = 100,
116-
.wiFiBand = WiFiBandEnum::k2g4,
117-
.rssi = 15,
118-
}
119-
92+
TestResponseIterator<3> fakeResponses{
93+
WiFiScanResponse{ .security = BitFlags<WiFiSecurityBitmap>(WiFiSecurityBitmap::kWpa2Personal),
94+
.ssid = { 'f', 'o', 'o', 0 },
95+
.ssidLen = 3,
96+
.bssid = { '1', '2', '3', '4', 0 },
97+
.channel = 123,
98+
.wiFiBand = WiFiBandEnum::k5g,
99+
.signal = { .type = WirelessSignalType::kdBm, .strength = 10 } },
100+
WiFiScanResponse{ .security = BitFlags<WiFiSecurityBitmap>(WiFiSecurityBitmap::kWpa2Personal),
101+
.ssid = { 'b', 'a', 'r', 0 },
102+
.ssidLen = 3,
103+
.bssid = { 'x', 'y', 'z', 0 },
104+
.channel = 321,
105+
.wiFiBand = WiFiBandEnum::k2g4,
106+
.signal = { .type = WirelessSignalType::kdBm, .strength = 20 } },
107+
WiFiScanResponse{ .security = BitFlags<WiFiSecurityBitmap>(WiFiSecurityBitmap::kWpa2Personal),
108+
.ssid = { 'b', 'a', 0 },
109+
.ssidLen = 2,
110+
.bssid = { 'z', 'z', 'z', 0 },
111+
.channel = 100,
112+
.wiFiBand = WiFiBandEnum::k2g4,
113+
.signal = { .type = WirelessSignalType::kdBm, .strength = 15 } }
120114
};
121115
WifiScanResponseToTLV encoder(NetworkCommissioningStatusEnum::kSuccess, ""_span, &fakeResponses);
122116

src/include/platform/NetworkCommissioning.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,57 @@ struct Network
9595
static_assert(sizeof(Network::networkID) <= std::numeric_limits<decltype(Network::networkIDLen)>::max(),
9696
"Max length of networkID ssid exceeds the limit of networkIDLen field");
9797

98+
/**
99+
* Wireless signal strength assessment or measurement type.
100+
*/
101+
enum class WirelessSignalType
102+
{
103+
/**
104+
* No signal strength information available.
105+
*/
106+
kNone,
107+
108+
/**
109+
* Signal strength is quantitative, in dBm.
110+
*/
111+
kdBm,
112+
113+
/**
114+
* Signal strength is qualitative, increasing from 0 (none/worst)
115+
* to 100 (best).
116+
*/
117+
kQualitative
118+
};
119+
120+
/**
121+
* Wireless signal type and strength assessment.
122+
*/
123+
struct WirelessSignal
124+
{
125+
/**
126+
* Wireless signal strength assessment or measurement type.
127+
*
128+
* This determines how to interpret @a strength.
129+
*/
130+
WirelessSignalType type;
131+
132+
/**
133+
* Wireless signal strength assessment or measurement.
134+
*
135+
* This is interpretted based on @a type.
136+
*/
137+
int8_t strength;
138+
};
139+
98140
struct WiFiScanResponse
99141
{
100-
public:
101142
chip::BitFlags<app::Clusters::NetworkCommissioning::WiFiSecurityBitmap> security;
102143
uint8_t ssid[DeviceLayer::Internal::kMaxWiFiSSIDLength];
103144
uint8_t ssidLen;
104145
uint8_t bssid[6];
105146
uint16_t channel;
106147
app::Clusters::NetworkCommissioning::WiFiBandEnum wiFiBand;
107-
int8_t rssi;
148+
WirelessSignal signal;
108149
};
109150

110151
static_assert(sizeof(WiFiScanResponse::ssid) <= std::numeric_limits<decltype(WiFiScanResponse::ssidLen)>::max(),

src/platform/ASR/NetworkCommissioningDriver.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ class ASRScanResponseIterator : public Iterator<WiFiScanResponse>
5656
item.security.SetRaw(mpScanResults[mIternum].security);
5757
item.ssidLen = static_cast<uint8_t>(
5858
strnlen(reinterpret_cast<const char *>(mpScanResults[mIternum].ssid), chip::DeviceLayer::Internal::kMaxWiFiSSIDLength));
59-
item.channel = mpScanResults[mIternum].channel;
60-
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
61-
item.rssi = mpScanResults[mIternum].ap_power;
59+
item.channel = mpScanResults[mIternum].channel;
60+
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
61+
item.signal.type = NetworkCommissioning::WirelessSignalType::kdBm;
62+
item.signal.strength = mpScanResults[mIternum].ap_power;
6263
memcpy(item.ssid, mpScanResults[mIternum].ssid, item.ssidLen);
6364
memcpy(item.bssid, mpScanResults[mIternum].bssid, 6);
6465

src/platform/Ameba/NetworkCommissioningDriver.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ class AmebaScanResponseIterator : public Iterator<WiFiScanResponse>
4343

4444
// copy the available information into WiFiScanResponse struct, which will be copied to the result to be sent
4545
item.security.SetRaw(mpScanResults[mIternum].security);
46-
item.ssidLen = mpScanResults[mIternum].SSID.len;
47-
item.channel = mpScanResults[mIternum].channel;
48-
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
49-
item.rssi = mpScanResults[mIternum].signal_strength;
46+
item.ssidLen = mpScanResults[mIternum].SSID.len;
47+
item.channel = mpScanResults[mIternum].channel;
48+
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
49+
item.signal.type = NetworkCommissioning::WirelessSignalType::kdBm;
50+
item.signal.strength = mpScanResults[mIternum].signal_strength;
5051
memcpy(item.ssid, mpScanResults[mIternum].SSID.val, item.ssidLen);
5152
memcpy(item.bssid, mpScanResults[mIternum].BSSID.octet, 6);
5253

src/platform/Beken/NetworkCommissioningDriver.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ class BKScanResponseIterator : public Iterator<WiFiScanResponse>
4444
}
4545
uint8_t ssidlenth = strlen(mpScanResults->aps[mIternum].ssid);
4646
item.security.SetRaw(NC_SECURITYCONVERT(mpScanResults->aps[mIternum].security));
47-
item.ssidLen = ssidlenth;
48-
item.channel = mpScanResults->aps[mIternum].channel;
49-
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
50-
item.rssi = mpScanResults->aps[mIternum].rssi;
47+
item.ssidLen = ssidlenth;
48+
item.channel = mpScanResults->aps[mIternum].channel;
49+
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
50+
item.signal.type = NetworkCommissioning::WirelessSignalType::kdBm;
51+
item.signal.strength = mpScanResults->aps[mIternum].rssi;
5152
memcpy(item.ssid, mpScanResults->aps[mIternum].ssid, ssidlenth);
5253
memcpy(item.bssid, mpScanResults->aps[mIternum].bssid, 6);
5354

src/platform/Darwin/WiFi/NetworkCommissioningWiFiDriver.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ void CopyNetworkInformationTo(WiFiScanResponse & destination, CWNetwork * source
7575
destination.security = GetWiFiSecurity(source);
7676
destination.channel = static_cast<uint16_t>(source.wlanChannel.channelNumber);
7777
destination.wiFiBand = GetWiFiBand(source.wlanChannel);
78-
destination.rssi = static_cast<int8_t>(source.rssiValue);
78+
destination.signal.type = NetworkCommissioning::WirelessSignalType::kdBm;
79+
destination.signal.strength = static_cast<int8_t>(source.rssiValue);
7980

8081
NSData * ssidData = source.ssidData;
8182
destination.ssidLen = static_cast<uint8_t>(std::min(ssidData.length, DeviceLayer::Internal::kMaxWiFiSSIDLength));

src/platform/ESP32/NetworkCommissioningDriver.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ class ESPScanResponseIterator : public Iterator<WiFiScanResponse>
8080
static_assert(chip::DeviceLayer::Internal::kMaxWiFiSSIDLength <= UINT8_MAX, "SSID length might not fit in item.ssidLen");
8181
item.ssidLen = static_cast<uint8_t>(
8282
strnlen(reinterpret_cast<const char *>(ap_record.ssid), chip::DeviceLayer::Internal::kMaxWiFiSSIDLength));
83-
item.channel = ap_record.primary;
84-
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
85-
item.rssi = ap_record.rssi;
83+
item.channel = ap_record.primary;
84+
item.wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4;
85+
item.signal.type = NetworkCommissioning::WirelessSignalType::kdBm;
86+
item.signal.strength = ap_record.rssi;
8687
memcpy(item.ssid, ap_record.ssid, item.ssidLen);
8788
memcpy(item.bssid, ap_record.bssid, sizeof(item.bssid));
8889
}

src/platform/Infineon/PSOC6/NetworkCommissioningDriver.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ class P6ScanResponseIterator : public Iterator<WiFiScanResponse>
4747
item.security.SetRaw(mpScanResults[mIternum].security);
4848
item.ssidLen =
4949
strnlen(reinterpret_cast<const char *>(mpScanResults[mIternum].SSID), chip::DeviceLayer::Internal::kMaxWiFiSSIDLength);
50-
item.channel = mpScanResults[mIternum].channel;
51-
item.wiFiBand = (mpScanResults[mIternum].band == CY_WCM_WIFI_BAND_2_4GHZ)
52-
? chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4
53-
: chip::DeviceLayer::NetworkCommissioning::WiFiBand::k5g;
54-
item.rssi = mpScanResults[mIternum].signal_strength;
50+
item.channel = mpScanResults[mIternum].channel;
51+
item.wiFiBand = (mpScanResults[mIternum].band == CY_WCM_WIFI_BAND_2_4GHZ)
52+
? chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4
53+
: chip::DeviceLayer::NetworkCommissioning::WiFiBand::k5g;
54+
item.signal.type = NetworkCommissioning::WirelessSignalType::kdBm;
55+
item.signal.strength = mpScanResults[mIternum].signal_strength;
5556
memcpy(item.ssid, mpScanResults[mIternum].SSID, item.ssidLen);
5657
memcpy(item.bssid, mpScanResults[mIternum].BSSID, 6);
5758

src/platform/Linux/ConnectivityManagerImpl_NetworkManagementWpaSupplicant.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,18 +1498,19 @@ bool ConnectivityManagerImpl::_GetBssInfo(const gchar * bssPath, NetworkCommissi
14981498
VerifyOrReturnError(bssidLen == kWiFiBSSIDLength, false);
14991499
memcpy(result.ssid, ssidStr, ssidLen);
15001500
memcpy(result.bssid, bssidBuf, bssidLen);
1501-
result.ssidLen = ssidLen;
1501+
result.ssidLen = ssidLen;
1502+
result.signal.type = NetworkCommissioning::WirelessSignalType::kdBm;
15021503
if (signal < INT8_MIN)
15031504
{
1504-
result.rssi = INT8_MIN;
1505+
result.signal.strength = INT8_MIN;
15051506
}
15061507
else if (signal > INT8_MAX)
15071508
{
1508-
result.rssi = INT8_MAX;
1509+
result.signal.strength = INT8_MAX;
15091510
}
15101511
else
15111512
{
1512-
result.rssi = static_cast<uint8_t>(signal);
1513+
result.signal.strength = static_cast<uint8_t>(signal);
15131514
}
15141515

15151516
auto bandInfo = GetBandAndChannelFromFrequency(frequency);

0 commit comments

Comments
 (0)