src/connectivity/wlan/drivers/third_party/broadcom/brcmfmac/common.cc
/* Search through the given country code table and issue the iovar */
Search through the given country code table and issue the iovar
Search through the given country code table and issue the iovar
zx_status_t brcmf_set_country(brcmf_pub* drvr, const wlanphy_country_t* country) {
  if (country == nullptr) {
    return ZX_ERR_INVALID_ARGS;
  }
  struct brcmf_if* ifp = brcmf_get_ifp(drvr, 0);
  wifi_config_t config;
  struct brcmf_fil_country_le ccreq;
  zx_status_t err;
  bcme_status_t fw_err = BCME_OK;
  const unsigned char* code = country->alpha2;
  int i;
  BRCMF_DBG(TRACE, "Enter: code=%c%c", code[0], code[1]);
  err = brcmf_get_meta_data(ifp, &config);
  if (err != ZX_OK) {
    return err;
  }
  ccreq.rev = 0;
  for (i = 0; i < MAX_CC_TABLE_ENTRIES; i++) {
    if (config.cc_table[i].cc_abbr[0] == 0) {
      BRCMF_ERR("Failed to find ccode %c%c in table", code[0], code[1]);
      return ZX_ERR_NOT_FOUND;
    }
    if (memcmp(config.cc_table[i].cc_abbr, code, WLANPHY_ALPHA2_LEN) == 0) {
      ccreq.rev = config.cc_table[i].cc_rev;
      break;
    }
  }
  ccreq.ccode[0] = code[0];
  ccreq.ccode[1] = code[1];
  ccreq.ccode[2] = 0;
  ccreq.country_abbrev[0] = code[0];
  ccreq.country_abbrev[1] = code[1];
  ccreq.country_abbrev[2] = 0;
  BRCMF_INFO("Country code set ccode %s, abbrev %s, rev %d", ccreq.ccode, ccreq.country_abbrev,
             ccreq.rev);
  err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq), &fw_err);
  if (err != ZX_OK) {
    BRCMF_ERR("Firmware rejected country setting: %s fw err %s", zx_status_get_string(err),
              brcmf_fil_get_errstr(fw_err));
  }
  return err;
}
zx_status_t brcmf_set_country ( brcmf_pub * drvr , const wlanphy_country_t * country ) { if ( country == nullptr ) { return ZX_ERR_INVALID_ARGS ; } struct brcmf_if * ifp = brcmf_get_ifp ( drvr , 0 ) ; wifi_config_t config ; struct brcmf_fil_country_le ccreq ; zx_status_t err ; bcme_status_t fw_err = BCME_OK ; const unsigned char * code = country -> alpha2 ; int i ; BRCMF_DBG ( TRACE , " " , code [ 0 ] , code [ 1 ] ) ; err = brcmf_get_meta_data ( ifp , & config ) ; if ( err != ZX_OK ) { return err ; } ccreq . rev = 0 ; for ( i = 0 ; i < MAX_CC_TABLE_ENTRIES ; i ++ ) { if ( config . cc_table [ i ] . cc_abbr [ 0 ] == 0 ) { BRCMF_ERR ( " " , code [ 0 ] , code [ 1 ] ) ; return ZX_ERR_NOT_FOUND ; } if ( memcmp ( config . cc_table [ i ] . cc_abbr , code , WLANPHY_ALPHA2_LEN ) == 0 ) { ccreq . rev = config . cc_table [ i ] . cc_rev ; break ; } } ccreq . ccode [ 0 ] = code [ 0 ] ; ccreq . ccode [ 1 ] = code [ 1 ] ; ccreq . ccode [ 2 ] = 0 ; ccreq . country_abbrev [ 0 ] = code [ 0 ] ; ccreq . country_abbrev [ 1 ] = code [ 1 ] ; ccreq . country_abbrev [ 2 ] = 0 ; BRCMF_INFO ( " " , ccreq . ccode , ccreq . country_abbrev , ccreq . rev ) ; err = brcmf_fil_iovar_data_set ( ifp , " " , & ccreq , sizeof ( ccreq ) , & fw_err ) ; if ( err != ZX_OK ) { BRCMF_ERR ( " " , zx_status_get_string ( err ) , brcmf_fil_get_errstr ( fw_err ) ) ; } return err ; }
Search through the given country code table and issue the iovar
Search through the given country code table and issue the iovar
// Get Broadcom WiFi Metadata by calling the bus specific function // This is the default value in case the relevant entry is not found in the table. // Search through the table until a valid or Null entry is found // It appears brcm firmware expects ccode and country_abbrev to have the same value // Log out the country code settings for reference // Set the country info in firmware