Skip to content

Commit

Permalink
Refactor case-statement to if-statement to avoid implicit fallback. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bnpfeife authored and harshavardhana committed Oct 2, 2019
1 parent 4235b0e commit fa68771
Showing 1 changed file with 43 additions and 30 deletions.
73 changes: 43 additions & 30 deletions core/rtw_mlme_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ static void _mgt_dispatcher(_adapter *padapter, struct mlme_handler *ptable, uni

void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame)
{
int subtype;

int index;
struct mlme_handler *ptable;
#ifdef CONFIG_AP_MODE
Expand Down Expand Up @@ -751,50 +753,61 @@ void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame)
#endif

#ifdef CONFIG_AP_MODE
switch (GetFrameSubType(pframe)) {
case WIFI_AUTH:
subtype = GetFrameSubType(pframe);
if ((subtype == WIFI_AUTH) ||
(subtype == WIFI_ASSOCREQ) ||
(subtype == WIFI_REASSOCREQ))
{
if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
{
ptable->func = &OnAuth;
}
else
{
ptable->func = &OnAuthClient;
//pass through
case WIFI_ASSOCREQ:
case WIFI_REASSOCREQ:
_mgt_dispatcher(padapter, ptable, precv_frame);
#ifdef CONFIG_HOSTAPD_MLME
if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
rtw_hostapd_mlme_rx(padapter, precv_frame);
#endif
break;
case WIFI_PROBEREQ:
if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
#ifdef CONFIG_HOSTAPD_MLME
rtw_hostapd_mlme_rx(padapter, precv_frame);
#else
}

// fallthrough
if ((subtype == WIFI_ASSOCREQ) ||
(subtype == WIFI_REASSOCREQ))
{
_mgt_dispatcher(padapter, ptable, precv_frame);
#endif
} else

if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
{
rtw_hostapd_mlme_rx(padapter, precv_frame);
}
}
}
else if (subtype == WIFI_PROBEREQ)
{
if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
#ifdef CONFIG_HOSTAPD_MLME
rtw_hostapd_mlme_rx(padapter, precv_frame);
#else
_mgt_dispatcher(padapter, ptable, precv_frame);
#endif
}
else
{
_mgt_dispatcher(padapter, ptable, precv_frame);
break;
case WIFI_BEACON:
_mgt_dispatcher(padapter, ptable, precv_frame);
break;
case WIFI_ACTION:
//if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
}
} else if (subtype == WIFI_BEACON ||
subtype == WIFI_ACTION)
{
_mgt_dispatcher(padapter, ptable, precv_frame);
break;
default:
}
else
{
_mgt_dispatcher(padapter, ptable, precv_frame);
if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
{
rtw_hostapd_mlme_rx(padapter, precv_frame);
break;
}
}
#else

_mgt_dispatcher(padapter, ptable, precv_frame);

#endif

}

#ifdef CONFIG_P2P
Expand Down

3 comments on commit fa68771

@juan-zaratiegui-aai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I apply this commit, my WiFi connection will never complete.
Reverting to the previous commit, everything works perfectly.
If you need any extra information, do not hesitate to ask me.
Thx

@mikedld
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juan-zaratiegui-aai, didn't try it myself yet but wouldn't be surprised given that old code wasn't overriding ptable->func for WIFI_ASSOCREQ and WIFI_REASSOCREQ, only for WIFI_AUTH. Looking at function names used (OnAuth and OnAuthClient), it's reasonable to guess that they're meant for WIFI_AUTH alone.

Not sure what exactly was wrong with the fallthrough in the first place. If compiler is bothered with it being implicit but humans aren't, there's a way to make it explicit (see documentation). @bnpfeife, @harshavardhana, would you care to comment?

@bnpfeife
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikedld
I agree with your assessment. I mucked up the logic during the conversion. So, I've created a PR #324 that reverts the original commit and uses the explicit fallthrough attribute.

Please sign in to comment.