Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
framework: tlvf: swap enum types
Browse files Browse the repository at this point in the history
eMediaType is a 16-bit enum, so it must be swapped. This is currently
not done, which results in the wrong values sent over the wire.

To fix this, do swapping for all enums, based on the size of the type.
This does result in redundant swaps for the 8-bit enums, but that is
negligible. In addition, tlvf_swap is inlined anyway so when optimising
the code will be removed entirely.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <[email protected]>
  • Loading branch information
arnout committed Feb 13, 2020
1 parent ac60d74 commit 1bc4134
Show file tree
Hide file tree
Showing 25 changed files with 361 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ typedef struct sWifiCredentials {
uint8_t force;
uint8_t radio_dir;
void struct_swap(){
tlvf_swap(8*sizeof(eWiFiSec), reinterpret_cast<uint8_t*>(&wifi_sec));
}
void struct_init(){
}
Expand Down Expand Up @@ -1133,6 +1134,8 @@ typedef struct sSteeringEvDisconnect {
client_mac.struct_swap();
bssid.struct_swap();
tlvf_swap(32, reinterpret_cast<uint8_t*>(&reason));
tlvf_swap(8*sizeof(eDisconnectSource), reinterpret_cast<uint8_t*>(&source));
tlvf_swap(8*sizeof(eDisconnectType), reinterpret_cast<uint8_t*>(&type));
}
void struct_init(){
client_mac.struct_init();
Expand Down Expand Up @@ -1165,6 +1168,9 @@ typedef struct sSteeringEvSnrXing {
client_mac.struct_swap();
bssid.struct_swap();
tlvf_swap(32, reinterpret_cast<uint8_t*>(&snr));
tlvf_swap(8*sizeof(eSteeringSnrChange), reinterpret_cast<uint8_t*>(&inactveXing));
tlvf_swap(8*sizeof(eSteeringSnrChange), reinterpret_cast<uint8_t*>(&highXing));
tlvf_swap(8*sizeof(eSteeringSnrChange), reinterpret_cast<uint8_t*>(&lowXing));
}
void struct_init(){
client_mac.struct_init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ uint8_t& tlvVsClientAssociationEvent::disconnect_type() {

void tlvVsClientAssociationEvent::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_1905_VS), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
m_bssid->struct_swap();
m_capabilities->struct_swap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ sMacAddr& cACTION_APMANAGER_4ADDR_STA_JOINED::dst_mac() {

void cACTION_APMANAGER_4ADDR_STA_JOINED::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_src_mac->struct_swap();
m_dst_mac->struct_swap();
}
Expand Down Expand Up @@ -116,6 +117,7 @@ sApChannelSwitch& cACTION_APMANAGER_JOINED_NOTIFICATION::cs_params() {

void cACTION_APMANAGER_JOINED_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
m_cs_params->struct_swap();
}
Expand Down Expand Up @@ -201,6 +203,7 @@ uint8_t& cACTION_APMANAGER_ENABLE_APS_REQUEST::center_channel() {

void cACTION_APMANAGER_ENABLE_APS_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
tlvf_swap(32, reinterpret_cast<uint8_t*>(m_bandwidth));
}

Expand Down Expand Up @@ -281,6 +284,7 @@ uint8_t& cACTION_APMANAGER_ENABLE_APS_RESPONSE::success() {

void cACTION_APMANAGER_ENABLE_APS_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_ENABLE_APS_RESPONSE::finalize()
Expand Down Expand Up @@ -344,6 +348,7 @@ cACTION_APMANAGER_INIT_DONE_NOTIFICATION::~cACTION_APMANAGER_INIT_DONE_NOTIFICAT
}
void cACTION_APMANAGER_INIT_DONE_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_INIT_DONE_NOTIFICATION::finalize()
Expand Down Expand Up @@ -405,6 +410,7 @@ sApSetRestrictedFailsafe& cACTION_APMANAGER_HOSTAP_SET_RESTRICTED_FAILSAFE_CHANN

void cACTION_APMANAGER_HOSTAP_SET_RESTRICTED_FAILSAFE_CHANNEL_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -474,6 +480,7 @@ uint8_t& cACTION_APMANAGER_HOSTAP_SET_RESTRICTED_FAILSAFE_CHANNEL_RESPONSE::succ

void cACTION_APMANAGER_HOSTAP_SET_RESTRICTED_FAILSAFE_CHANNEL_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_HOSTAP_SET_RESTRICTED_FAILSAFE_CHANNEL_RESPONSE::finalize()
Expand Down Expand Up @@ -541,6 +548,7 @@ int8_t& cACTION_APMANAGER_HOSTAP_AP_DISABLED_NOTIFICATION::vap_id() {

void cACTION_APMANAGER_HOSTAP_AP_DISABLED_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_HOSTAP_AP_DISABLED_NOTIFICATION::finalize()
Expand Down Expand Up @@ -612,6 +620,7 @@ sVapInfo& cACTION_APMANAGER_HOSTAP_AP_ENABLED_NOTIFICATION::vap_info() {

void cACTION_APMANAGER_HOSTAP_AP_ENABLED_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_vap_info->struct_swap();
}

Expand Down Expand Up @@ -683,6 +692,7 @@ cACTION_APMANAGER_HOSTAP_VAPS_LIST_UPDATE_REQUEST::~cACTION_APMANAGER_HOSTAP_VAP
}
void cACTION_APMANAGER_HOSTAP_VAPS_LIST_UPDATE_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_HOSTAP_VAPS_LIST_UPDATE_REQUEST::finalize()
Expand Down Expand Up @@ -740,6 +750,7 @@ cACTION_APMANAGER_HOSTAP_GENERATE_CLIENT_ASSOCIATION_NOTIFICATIONS_REQUEST::~cAC
}
void cACTION_APMANAGER_HOSTAP_GENERATE_CLIENT_ASSOCIATION_NOTIFICATIONS_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_HOSTAP_GENERATE_CLIENT_ASSOCIATION_NOTIFICATIONS_REQUEST::finalize()
Expand Down Expand Up @@ -801,6 +812,7 @@ sVapsList& cACTION_APMANAGER_HOSTAP_VAPS_LIST_UPDATE_NOTIFICATION::params() {

void cACTION_APMANAGER_HOSTAP_VAPS_LIST_UPDATE_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -870,6 +882,7 @@ sApChannelSwitch& cACTION_APMANAGER_HOSTAP_CHANNEL_SWITCH_ACS_START::cs_params()

void cACTION_APMANAGER_HOSTAP_CHANNEL_SWITCH_ACS_START::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_cs_params->struct_swap();
}

Expand Down Expand Up @@ -939,6 +952,7 @@ sApChannelSwitch& cACTION_APMANAGER_HOSTAP_CSA_ERROR_NOTIFICATION::cs_params() {

void cACTION_APMANAGER_HOSTAP_CSA_ERROR_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_cs_params->struct_swap();
}

Expand Down Expand Up @@ -1008,6 +1022,7 @@ sApChannelSwitch& cACTION_APMANAGER_HOSTAP_CSA_NOTIFICATION::cs_params() {

void cACTION_APMANAGER_HOSTAP_CSA_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_cs_params->struct_swap();
}

Expand Down Expand Up @@ -1077,6 +1092,7 @@ sApChannelSwitch& cACTION_APMANAGER_HOSTAP_ACS_ERROR_NOTIFICATION::cs_params() {

void cACTION_APMANAGER_HOSTAP_ACS_ERROR_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_cs_params->struct_swap();
}

Expand Down Expand Up @@ -1155,6 +1171,7 @@ std::tuple<bool, beerocks::message::sWifiChannel&> cACTION_APMANAGER_HOSTAP_ACS_

void cACTION_APMANAGER_HOSTAP_ACS_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_cs_params->struct_swap();
for (size_t i = 0; i < beerocks::message::SUPPORTED_CHANNELS_LENGTH; i++){
m_supported_channels_list[i].struct_swap();
Expand Down Expand Up @@ -1237,6 +1254,7 @@ sDfsCacCompleted& cACTION_APMANAGER_HOSTAP_DFS_CAC_COMPLETED_NOTIFICATION::param

void cACTION_APMANAGER_HOSTAP_DFS_CAC_COMPLETED_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -1306,6 +1324,7 @@ sDfsChannelAvailable& cACTION_APMANAGER_HOSTAP_DFS_CHANNEL_AVAILABLE_NOTIFICATIO

void cACTION_APMANAGER_HOSTAP_DFS_CHANNEL_AVAILABLE_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -1375,6 +1394,7 @@ sMacAddr& cACTION_APMANAGER_HOSTAP_ADD_4ADDR_STA_UPDATE::mac() {

void cACTION_APMANAGER_HOSTAP_ADD_4ADDR_STA_UPDATE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
}

Expand Down Expand Up @@ -1444,6 +1464,7 @@ sMacAddr& cACTION_APMANAGER_HOSTAP_DEL_4ADDR_STA_UPDATE::mac() {

void cACTION_APMANAGER_HOSTAP_DEL_4ADDR_STA_UPDATE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
}

Expand Down Expand Up @@ -1513,6 +1534,7 @@ sNeighborSetParams11k& cACTION_APMANAGER_HOSTAP_SET_NEIGHBOR_11K_REQUEST::params

void cACTION_APMANAGER_HOSTAP_SET_NEIGHBOR_11K_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -1582,6 +1604,7 @@ sNeighborRemoveParams11k& cACTION_APMANAGER_HOSTAP_REMOVE_NEIGHBOR_11K_REQUEST::

void cACTION_APMANAGER_HOSTAP_REMOVE_NEIGHBOR_11K_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -1651,6 +1674,7 @@ sClientAssociationParams& cACTION_APMANAGER_CLIENT_ASSOCIATED_NOTIFICATION::para

void cACTION_APMANAGER_CLIENT_ASSOCIATED_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -1720,6 +1744,7 @@ sClientDisconnectionParams& cACTION_APMANAGER_CLIENT_DISCONNECTED_NOTIFICATION::

void cACTION_APMANAGER_CLIENT_DISCONNECTED_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -1801,7 +1826,9 @@ uint32_t& cACTION_APMANAGER_CLIENT_DISCONNECT_REQUEST::reason() {

void cACTION_APMANAGER_CLIENT_DISCONNECT_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
tlvf_swap(8*sizeof(eDisconnectType), reinterpret_cast<uint8_t*>(m_type));
tlvf_swap(32, reinterpret_cast<uint8_t*>(m_reason));
}

Expand Down Expand Up @@ -1889,6 +1916,7 @@ sClientDisconnectResponse& cACTION_APMANAGER_CLIENT_DISCONNECT_RESPONSE::params(

void cACTION_APMANAGER_CLIENT_DISCONNECT_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -1962,6 +1990,7 @@ sMacAddr& cACTION_APMANAGER_CLIENT_DISALLOW_REQUEST::bssid() {

void cACTION_APMANAGER_CLIENT_DISALLOW_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
m_bssid->struct_swap();
}
Expand Down Expand Up @@ -2043,6 +2072,7 @@ sMacAddr& cACTION_APMANAGER_CLIENT_ALLOW_REQUEST::bssid() {

void cACTION_APMANAGER_CLIENT_ALLOW_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
m_bssid->struct_swap();
}
Expand Down Expand Up @@ -2120,6 +2150,7 @@ sNodeRssiMeasurementRequest& cACTION_APMANAGER_CLIENT_RX_RSSI_MEASUREMENT_REQUES

void cACTION_APMANAGER_CLIENT_RX_RSSI_MEASUREMENT_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2189,6 +2220,7 @@ sNodeRssiMeasurement& cACTION_APMANAGER_CLIENT_RX_RSSI_MEASUREMENT_RESPONSE::par

void cACTION_APMANAGER_CLIENT_RX_RSSI_MEASUREMENT_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2258,6 +2290,7 @@ sMacAddr& cACTION_APMANAGER_CLIENT_IRE_CONNECTED_NOTIFICATION::mac() {

void cACTION_APMANAGER_CLIENT_IRE_CONNECTED_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
}

Expand Down Expand Up @@ -2331,6 +2364,7 @@ sMacAddr& cACTION_APMANAGER_ACK::sta_mac() {

void cACTION_APMANAGER_ACK::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_sta_mac->struct_swap();
}

Expand Down Expand Up @@ -2406,6 +2440,7 @@ sNodeBssSteerRequest& cACTION_APMANAGER_CLIENT_BSS_STEER_REQUEST::params() {

void cACTION_APMANAGER_CLIENT_BSS_STEER_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2475,6 +2510,7 @@ sNodeBssSteerResponse& cACTION_APMANAGER_CLIENT_BSS_STEER_RESPONSE::params() {

void cACTION_APMANAGER_CLIENT_BSS_STEER_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2544,6 +2580,7 @@ sMacAddr& cACTION_APMANAGER_CLIENT_RX_RSSI_MEASUREMENT_CMD_RESPONSE::mac() {

void cACTION_APMANAGER_CLIENT_RX_RSSI_MEASUREMENT_CMD_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_mac->struct_swap();
}

Expand Down Expand Up @@ -2613,6 +2650,7 @@ sSteeringClientSetRequest& cACTION_APMANAGER_STEERING_CLIENT_SET_REQUEST::params

void cACTION_APMANAGER_STEERING_CLIENT_SET_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2682,6 +2720,7 @@ sSteeringClientSetResponse& cACTION_APMANAGER_STEERING_CLIENT_SET_RESPONSE::para

void cACTION_APMANAGER_STEERING_CLIENT_SET_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2751,6 +2790,7 @@ sSteeringEvProbeReq& cACTION_APMANAGER_STEERING_EVENT_PROBE_REQ_NOTIFICATION::pa

void cACTION_APMANAGER_STEERING_EVENT_PROBE_REQ_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2820,6 +2860,7 @@ sSteeringEvAuthFail& cACTION_APMANAGER_STEERING_EVENT_AUTH_FAIL_NOTIFICATION::pa

void cACTION_APMANAGER_STEERING_EVENT_AUTH_FAIL_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
m_params->struct_swap();
}

Expand Down Expand Up @@ -2955,6 +2996,7 @@ bool cACTION_APMANAGER_WIFI_CREDENTIALS_UPDATE_REQUEST::add_wifi_credentials(std

void cACTION_APMANAGER_WIFI_CREDENTIALS_UPDATE_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
for (size_t i = 0; i < (size_t)*m_wifi_credentials_size; i++){
std::get<1>(wifi_credentials(i)).class_swap();
}
Expand Down Expand Up @@ -3038,6 +3080,7 @@ cACTION_APMANAGER_HEARTBEAT_NOTIFICATION::~cACTION_APMANAGER_HEARTBEAT_NOTIFICAT
}
void cACTION_APMANAGER_HEARTBEAT_NOTIFICATION::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_HEARTBEAT_NOTIFICATION::finalize()
Expand Down Expand Up @@ -3095,6 +3138,7 @@ cACTION_APMANAGER_READ_ACS_REPORT_REQUEST::~cACTION_APMANAGER_READ_ACS_REPORT_RE
}
void cACTION_APMANAGER_READ_ACS_REPORT_REQUEST::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
}

bool cACTION_APMANAGER_READ_ACS_REPORT_REQUEST::finalize()
Expand Down Expand Up @@ -3161,6 +3205,7 @@ std::tuple<bool, beerocks::message::sWifiChannel&> cACTION_APMANAGER_READ_ACS_RE

void cACTION_APMANAGER_READ_ACS_REPORT_RESPONSE::class_swap()
{
tlvf_swap(8*sizeof(eActionOp_APMANAGER), reinterpret_cast<uint8_t*>(m_action_op));
for (size_t i = 0; i < beerocks::message::SUPPORTED_CHANNELS_LENGTH; i++){
m_supported_channels_list[i].struct_swap();
}
Expand Down
Loading

0 comments on commit 1bc4134

Please sign in to comment.