Country Code information can be given to driver from:
1. DefaultCountryTablefield in WCNSS_qcom_wlan_nv.bin-read during driver initialization
2. gStaCountryCodeparameter in WCNSS_qcom_cfg.ini –read during driver initialization to replace default country code in WCNSS_qcom_wlan_nv.bin
3. Country IE from AP defined by 802.11d –information given by AP
4. “iwregset” command –set from userspaceapplication over cfg80211 interface
Private IOCTL with “COUNTRY” command –set from userspaceapplication over wextinterface
gCountryCodePriorityis a flag that can be defined in WCNSS_qcom_cfg.ini to decide the preferred priority of Country Code information between userspacecommands (either over cfg80211 interface or wextinterface) and 802.11d; the value can be
.1 –Country Code information from userspacecommands takes priority
Overall priority would be userspacecommands > 802.11d > gStaCountryCodein WCNSS_qcom_cfg.ini > DefaultCountryTablein WCNSS_qcom_wlan_nv.bin
This is the default setting
.0 –Country Code information from 802.11d takes priority
Overall priority would be 802.11d > userspacecommands > gStaCountryCodein WCNSS_qcom_cfg.ini > DefaultCountryTablein WCNSS_qcom_wlan_nv.bin
命令设置国家码
iw reg set CN
iw reg get
iwpriv wlan0 getChannelList
wpa_cli -i wlan0 driver COUNTRY CN
WCN36X0 Country Code from DefaultCountryTable field in WCNSS_qcom_wlan_nv.bin
WCN39X0 or QC61x4 Country Code from Regulatory Domain field in BDF file(/firmware/image/bdwlan.bin)
相关property
ro.boot.wificountrycode
gsm.operator.iso-country
设置
Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_COUNTRY_CODE);
framework
WifiManager.setCountryCode()
driver
wlan_reg_set_country
reg_set_country
frameworks/opt/telephony/src/java/com/android/internal/telephony/LocaleTracker.java
private synchronized void updateLocale() {
376 // If MCC is available from network service state, use it first.
377 String mcc = null;
378 String countryIso = "";
379 if (!TextUtils.isEmpty(mOperatorNumeric)) {
380 try {
381 mcc = mOperatorNumeric.substring(0, 3);
382 countryIso = MccTable.countryCodeForMcc(mcc);
383 } catch (StringIndexOutOfBoundsException ex) {
384 loge("updateLocale: Can't get country from operator numeric. mcc = "
385 + mcc + ". ex=" + ex);
386 }
387 }
388
389 // If for any reason we can't get country from operator numeric, try to get it from cell
390 // info.
391 if (TextUtils.isEmpty(countryIso)) {
392 mcc = getMccFromCellInfo();
393 countryIso = MccTable.countryCodeForMcc(mcc);
394 }
395
396 log("updateLocale: mcc = " + mcc + ", country = " + countryIso);
397 boolean countryChanged = false;
398 if (!Objects.equals(countryIso, mCurrentCountryIso)) {
399 String msg = "updateLocale: Change the current country to \"" + countryIso
400 + "\", mcc = " + mcc + ", mCellInfoList = " + mCellInfoList;
401 log(msg);
402 mLocalLog.log(msg);
403 mCurrentCountryIso = countryIso;
404
405 TelephonyManager.setTelephonyProperty(mPhone.getPhoneId(),
406 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, mCurrentCountryIso);
407
408 // Set the country code for wifi. This sets allowed wifi channels based on the
409 // country of the carrier we see. If we can't see any, reset to 0 so we don't
410 // broadcast on forbidden channels.
411 WifiManager wifiManager = (WifiManager) mPhone.getContext()
412 .getSystemService(Context.WIFI_SERVICE);
413 if (wifiManager != null) {
414 wifiManager.setCountryCode(countryIso);
415 } else {
416 msg = "Wifi manager is not available.";
417 log(msg);
418 mLocalLog.log(msg);
419 }
420
421
422 Intent intent = new Intent(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED);
423 intent.putExtra(TelephonyManager.EXTRA_NETWORK_COUNTRY, countryIso);
424 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
425 mPhone.getContext().sendBroadcast(intent);
426
427 countryChanged = true;
428 }
429
frameworks/opt/telephony/src/java/com/android/internal/telephony/Phone.java#581
// The locale from the "ro.carrier" system property or R.array.carrier_properties.
569 // This will be overwritten by the Locale from the SIM language settings (EF-PL, EF-LI)
570 // if applicable.
571 final Locale carrierLocale = getLocaleFromCarrierProperties(mContext);
572 if (carrierLocale != null && !TextUtils.isEmpty(carrierLocale.getCountry())) {
573 final String country = carrierLocale.getCountry();
574 try {
575 Settings.Global.getInt(mContext.getContentResolver(),
576 Settings.Global.WIFI_COUNTRY_CODE);
577 } catch (Settings.SettingNotFoundException e) {
578 // note this is not persisting
579 WifiManager wM = (WifiManager)
580 mContext.getSystemService(Context.WIFI_SERVICE);
581 wM.setCountryCode(country);
582 }
583 }
有一篇不错的文章
https://blog.csdn.net/zhangdaxia2/article/details/90545175 高通Android7.1 WIFI国家码问题