Skip to content

Commit

Permalink
Support Airport Country Code overriding(Since Mojave), the priority i…
Browse files Browse the repository at this point in the history
…s user_override_cc > firmware_cc > geo_location_cc. This feature let those cards(iwn, 3xxx, 7xxx, 8xxx) which don't support LAR to get the correct Country Code.
  • Loading branch information
zxystd committed Aug 2, 2021
1 parent 2d63f46 commit ebcd6a1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions AirportItlwm/AirportItlwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bool AirportItlwm::init(OSDictionary *properties)
bool ret = super::init(properties);
awdlSyncEnable = true;
power_state = 0;
memset(geo_location_cc, 0, sizeof(geo_location_cc));
return ret;
}

Expand Down
3 changes: 2 additions & 1 deletion AirportItlwm/AirportItlwm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ IOReturn set##REQ(OSObject *object, struct DATA_TYPE *data);
FUNC_IOCTL_GET(AP_IE_LIST, apple80211_ap_ie_data)
FUNC_IOCTL_GET(LINK_CHANGED_EVENT_DATA, apple80211_link_changed_event_data)
FUNC_IOCTL_GET(ASSOCIATION_STATUS, apple80211_assoc_status_data)
FUNC_IOCTL_GET(COUNTRY_CODE, apple80211_country_code_data)
FUNC_IOCTL(COUNTRY_CODE, apple80211_country_code_data)
FUNC_IOCTL_GET(RADIO_INFO, apple80211_radio_info_data)
FUNC_IOCTL_GET(MCS, apple80211_mcs_data)
FUNC_IOCTL_SET(VIRTUAL_IF_CREATE, apple80211_virt_if_create_data)
Expand Down Expand Up @@ -260,6 +260,7 @@ IOReturn set##REQ(OSObject *object, struct DATA_TYPE *data);
UInt64 currentSpeed;
UInt32 currentStatus;
bool disassocIsVoluntary;
char geo_location_cc[3];

IO80211P2PInterface *fP2PDISCInterface;
IO80211P2PInterface *fP2PGOInterface;
Expand Down
24 changes: 19 additions & 5 deletions AirportItlwm/AirportSTAIOCTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ SInt32 AirportItlwm::apple80211Request(unsigned int request_type,
IOCTL_GET(request_type, ASSOCIATION_STATUS, apple80211_assoc_status_data);
break;
case APPLE80211_IOC_COUNTRY_CODE: // 51
IOCTL_GET(request_type, COUNTRY_CODE, apple80211_country_code_data);
IOCTL(request_type, COUNTRY_CODE, apple80211_country_code_data);
break;
case APPLE80211_IOC_RADIO_INFO:
IOCTL_GET(request_type, RADIO_INFO, apple80211_radio_info_data);
Expand Down Expand Up @@ -1139,11 +1139,25 @@ IOReturn AirportItlwm::
getCOUNTRY_CODE(OSObject *object,
struct apple80211_country_code_data *cd)
{
char cc[3];
char user_override_cc[3];
const char *cc_fw = fHalService->getDriverInfo()->getFirmwareCountryCode();

cd->version = APPLE80211_VERSION;
memset(cc, 0, sizeof(cc));
PE_parse_boot_argn("itlwm_cc", cc, 3);
strncpy((char*)cd->cc, cc[0] == 0 ? fHalService->getDriverInfo()->getFirmwareCountryCode() : cc, sizeof(cd->cc));
memset(user_override_cc, 0, sizeof(user_override_cc));
PE_parse_boot_argn("itlwm_cc", user_override_cc, 3);
/* user_override_cc > firmware_cc > geo_location_cc */
strncpy((char*)cd->cc, user_override_cc[0] ? user_override_cc : ((cc_fw[0] == 'Z' && cc_fw[1] == 'Z' && geo_location_cc[0]) ? geo_location_cc : cc_fw), sizeof(cd->cc));
return kIOReturnSuccess;
}

IOReturn AirportItlwm::
setCOUNTRY_CODE(OSObject *object, struct apple80211_country_code_data *data)
{
XYLog("%s cc=%s\n", __FUNCTION__, data->cc);
if (data->cc[0] != 120 && data->cc[0] != 88) {
memcpy(geo_location_cc, data->cc, sizeof(geo_location_cc));
fNetIf->postMessage(APPLE80211_M_COUNTRY_CODE_CHANGED);
}
return kIOReturnSuccess;
}

Expand Down

0 comments on commit ebcd6a1

Please sign in to comment.