当前位置:   article > 正文

【笔记】APN 配置参数 bitmask 数据转换(Android & KaiOS)

【笔记】APN 配置参数 bitmask 数据转换(Android & KaiOS)

一、参数说明

(一)APN配置结构对比

平台AndroidKaiOS
文件类型xmljson
结构每个<apn>标签是一条APN,包含完成的信息层级数组结构,使用JSON格式的数据。最外层是mcc,其次mnc,最后APN用数组形式配置(每个APN都是一个对象,不含mccmnc属性)。
Android: apns-conf.xml
  1. <!-- Android: apns-conf.xml -->
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <apns version="8">
  4. <apn carrier="T-Mobile US" mcc="001" mnc="01" apn="fast.t-mobile.com" user="" password="" server="" proxy="" port="" mmsc="http://mms.msg.eng.t-mobile.com/mms/wapenc" mmsproxy="" mmsport="" type="default,mms,supl,hipri,xcap,rcs" protocol="IPV6" roaming_protocol="IP" bearer_bitmask="" mvno_type="ecid" mvno_match_data="[4]4310260" class="" user_visible="true" user_editable="true" authtype="0"/>
  5. </apns>
KaiOS: apns.json

特别需要注意格式(很容易出错),数组最后不用加逗号,注意大/中括号的首位一致性。

  1. {
  2. "202": {
  3. "10": [
  4. {"carrier":"Wind Internet","apn":"gint.b-online.gr","type":["default","supl"]},
  5. {"voicemail":"122","type":["operatorvariant"]},
  6. {"carrier":"Wind MMS","apn":"mnet.b-online.gr","mmsc":"http://192.168.200.95/servlets/mms","mmsproxy":"192.168.200.11","mmsport":"9401","type":["mms"]}
  7. ],
  8. "01": [
  9. {"carrier":"Cosmote Wireless Internet","apn":"","type":["ia"]},
  10. {"voicemail":"123","type":["operatorvariant"]},
  11. {"carrier":"Cosmote Wireless Internet","apn":"internet","type":["default","supl"]},
  12. {"carrier":"Cosmote Mms","apn":"mms","mmsc":"http://mmsc.cosmote.gr:8002","mmsproxy":"10.10.10.20","mmsport":"8080","type":["mms"]}
  13. ],
  14. "09": [
  15. {"carrier":"Q Internet","apn":"myq","type":["default","supl"]},
  16. {"voicemail":"122","type":["operatorvariant"]},
  17. {"carrier":"Q-Telecom MMS GPRS","apn":"q-mms.myq.gr","mmsc":"http://mms.myq.gr","mmsproxy":"192.168.80.134","mmsport":"8080","type":["mms"]}
  18. ]
  19. },
  20. "001": {
  21. "01": [
  22. {"carrier":"Testing SIM default","apn":"test","type":["default"],"protocol":"IPV4V6","roaming_protocol":"IPV4V6","user_visible":"true"},
  23. {"carrier":"IMS","apn":"ims","type":["ims"],"protocol":"IPV4V6","roaming_protocol":"IPV4V6","user_visible":"true"},
  24. {"carrier":"XCAP","apn":"xcap","type":["xcap"],"protocol":"IPV4V6","roaming_protocol":"IPV4V6","user_visible":"true","authtype":"0"}
  25. ]
  26. }
  27. }

(二)bearer配置值对比

  • 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20 (The original bearer value in Android,位运算)
  • 1048575(The original bearer value in KaiOS using decimalism)

二、代码解析

(一)Android

待完善

(二)KaiOS(DataCallManager.jsm)

1、bitmask的进制转换

可以参考PDN建立逻辑,gecko/dom/system/gonk/radio/DataCallManager.jsm

  1. //DataCallManager.jsm
  2. //检查对应的rat是否包含在此APN bearer 配置中
  3. // Check rat value include in the bit map or not.
  4. function bitmaskHasTech(aBearerBitmask, aRadioTech) {
  5. if (aBearerBitmask == 0) {
  6. return true;
  7. } else if (aRadioTech > 0) {
  8. return (aBearerBitmask & (1 << (aRadioTech - 1))) != 0;
  9. }
  10. return false;
  11. }
  12. //bearer十进制转成二进制
  13. // Show the detail rat type.
  14. function bitmaskToString(aBearerBitmask) {
  15. if (aBearerBitmask == 0 || aBearerBitmask === undefined) {
  16. return 0;
  17. }
  18. let val = "";
  19. for (let i = 1; i < RIL.GECKO_RADIO_TECH.length; i++) {
  20. if ((aBearerBitmask & (1 << (i - 1))) != 0) {
  21. val = val.concat(i + "|");
  22. }
  23. }
  24. return val;
  25. }
  26. function bearerBitmapHasCdma(aBearerBitmask) {
  27. return (RIL_RADIO_CDMA_TECHNOLOGY_BITMASK & aBearerBitmask) != 0;
  28. }

bitmaskToString接口中,将bitmask转化成String时,循环RIL.GECKO_RADIO_TECH的长度次,经过位运算转换成与Android原始配置的bearer_bitmask相同格式的bearer位符,用“|”间隔rat类型位。

是如何通过RIL调用ril_consts.js内的GECKO_RADIO_TECH?

DataCallManager.jsm 中定义RIL对象,并使用XPCOMUtils.defineLazyGetter()方法来实现懒加载,即在要使用时才加载和初始化对象(只有在第一次访问该对象时才会进行初始化和加载),避免不必要的性能开销和资源浪费。
RIL对象是通过ChromeUtils.import 方法从ril_consts.js文件中导入的,该对象由ril_consts.js文件中的代码创建和初始化的。

  1. //DataCallManaer.jsm
  2. "use strict";
  3. //XPCOM 是一个用于 实现跨语言组件的技术框架。
  4. //导入XPCOMUtils对象(工具库),简化和封装XPCOM组件的开发和使用。
  5. //使用常量const来定义 XPCOMUtils 对象,以确保在运行时不会发生对象被重新赋值的情况。
  6. const { XPCOMUtils } = ChromeUtils.import(
  7. "resource://gre/modules/XPCOMUtils.jsm"
  8. );
  9. //定义RIL对象,后续调用 RIL.GECKO_RADIO_TECH
  10. XPCOMUtils.defineLazyGetter(this, "RIL", function() {
  11. return ChromeUtils.import("resource://gre/modules/ril_consts.js");
  12. });
  13. //ref RIL.GECKO_RADIO_TECH
  14. const TCP_BUFFER_SIZES = [
  15. null,
  16. "4092,8760,48000,4096,8760,48000", // gprs
  17. "4093,26280,70800,4096,16384,70800", // edge
  18. "58254,349525,1048576,58254,349525,1048576", // umts
  19. "16384,32768,131072,4096,16384,102400", // is95a = 1xrtt
  20. "16384,32768,131072,4096,16384,102400", // is95b = 1xrtt
  21. "16384,32768,131072,4096,16384,102400", // 1xrtt
  22. "4094,87380,262144,4096,16384,262144", // evdo0
  23. "4094,87380,262144,4096,16384,262144", // evdoa
  24. "61167,367002,1101005,8738,52429,262114", // hsdpa
  25. "40778,244668,734003,16777,100663,301990", // hsupa = hspa
  26. "40778,244668,734003,16777,100663,301990", // hspa
  27. "4094,87380,262144,4096,16384,262144", // evdob
  28. "131072,262144,1048576,4096,16384,524288", // ehrpd
  29. "524288,1048576,2097152,262144,524288,1048576", // lte
  30. "122334,734003,2202010,32040,192239,576717", // hspa+
  31. "4096,87380,110208,4096,16384,110208", // gsm (using default value)
  32. "4096,87380,110208,4096,16384,110208", // tdscdma (using default value)
  33. "122334,734003,2202010,32040,192239,576717", // iwlan
  34. "122334,734003,2202010,32040,192239,576717", // ca
  35. ];
  36. //定义了一个常量RIL_RADIO_CDMA_TECHNOLOGY_BITMASK,用于表示CDMA射频技术类型的掩码值。
  37. //RIL.GECKO_RADIO_TECH.indexOf 查找各个CDMA技术类型在GECKO_RADIO_TECH数组中的下标值,
  38. //-1 的目的是得到对应的掩码位数,并将此转换成掩码值,
  39. //使用按位左移(<<)运算符得到掩码值,
  40. //各个掩码值按位或(|)操作得到最终的掩码值。
  41. const RIL_RADIO_CDMA_TECHNOLOGY_BITMASK =
  42. (1 << (RIL.GECKO_RADIO_TECH.indexOf("is95a") - 1)) |
  43. (1 << (RIL.GECKO_RADIO_TECH.indexOf("is95b") - 1)) |
  44. (1 << (RIL.GECKO_RADIO_TECH.indexOf("1xrtt") - 1)) |
  45. (1 << (RIL.GECKO_RADIO_TECH.indexOf("evdo0") - 1)) |
  46. (1 << (RIL.GECKO_RADIO_TECH.indexOf("evdoa") - 1)) |
  47. (1 << (RIL.GECKO_RADIO_TECH.indexOf("evdob") - 1)) |
  48. (1 << (RIL.GECKO_RADIO_TECH.indexOf("ehrpd") - 1));
  49. // set to true in ril_consts.js to see debug messages
  50. var DEBUG = RIL_DEBUG.DEBUG_RIL; //调试用的log打印标识符

如上代码,CDMA技术类型对应的掩码值RIL_RADIO_CDMA_TECHNO如下:

is95a: 1 << (5-1) = 0x10
is95b: 1 << (6-1) = 0x20
1xrtt: 1 << (7-1) = 0x40
evdo0: 1 << (8-1) = 0x80
evdoa: 1 << (9-1) = 0x100
evdob: 1 << (14-1) = 0x2000
ehrpd: 1 << (15-1) = 0x4000

2、GECKO_RADIO_TECH 定义网络制式 (ril_consts.js)

在KaiOS中,RIL.GECKO_RADIO_TECH数组是在Gecko内核的代码中定义的,其实现位于Gecko代码库的"gecko/dom/system/gonk/radio/ril_consts.js"文件中。该文件定义了一系列RIL层的常量,包括射频技术类型、消息ID等。在该文件中,可以找到以下代码片段,其中定义了RIL.GECKO_RADIO_TECH数组的元素和顺序:

  1. //GECKO_RADIO_TECH 数组定义射频技术(网络连接)
  2. this.GECKO_RADIO_TECH = [
  3. null,
  4. "gprs", //1 GPRS
  5. "edge", //2 EDGE
  6. "umts", //3 UMTS
  7. "is95a", //4 IS-95A
  8. "is95b", //5 IS-95B
  9. "1xrtt", //6 cdma1x?一种CDMA2000射频技术,是CDMAOne技术的升级版(1x Radio Transmission Technology)
  10. "evdo0", //7 EVDO-0
  11. "evdoa", //8 EVDO-A
  12. "hsdpa", //9
  13. "hsupa", //10
  14. "hspa", //11
  15. "evdob", //12 EVDO-B
  16. "ehrpd", //13 EVDO-D
  17. "lte", //14 LTE
  18. "hspa+", //15 HSPA+
  19. "gsm", //16 GSM
  20. "tdscdma", //17 TD-SCDMA
  21. "iwlan", //18 iWLAN(wifi)
  22. "lte_ca", //19 LTE_CA
  23. ];
  24. //定义遵循的协议类型
  25. this.GECKO_PROFILE_INFO_TYPE_COMMON = 0;
  26. this.GECKO_PROFILE_INFO_TYPE_3GPP = 1;
  27. this.GECKO_PROFILE_INFO_TYPE_3GPP2 = 2;
3、DataCall 对 rat 的使用案例
  1. dataRegistrationChanged(aRadioTech) {
  2. let targetBearer;
  3. if (this.apnSetting.bearer === undefined) {
  4. targetBearer = 0;
  5. } else {
  6. targetBearer = this.apnSetting.bearer;
  7. }
  8. if (DEBUG) {
  9. this.debug(
  10. "dataRegistrationChanged: targetBearer: " +
  11. bitmaskToString(targetBearer)
  12. );
  13. }
  14. if (bitmaskHasTech(targetBearer, aRadioTech)) {
  15. // Ignore same rat type. Let handler process the retry.
  16. } else {
  17. if (DEBUG) {
  18. this.debug(
  19. "dataRegistrationChanged: current APN do not support this rat reset DC. APN:" +
  20. JSON.stringify(this.apnSetting)
  21. );
  22. // Clean the requestedNetworkInterfaces due to current DC can not support this rat under DC retrying state.
  23. // Let handler process the retry.
  24. let targetRequestedNetworkInterfaces = this.requestedNetworkInterfaces.slice();
  25. for (let networkInterface of targetRequestedNetworkInterfaces) {
  26. this.disconnect(networkInterface);
  27. }
  28. }
  29. },

gecko/koost/telephony/TelephonyBinderService.h

  1. // Cover the GECKO_RADIO_TECH to NETWORK_TYPE_*
  2. int32_t convertRadioTech(const nsAString& rat);

三、日志分析

追溯在PDN建立过程中,读取apn配置的bearer参数到DataCall使用的radio类型的bearer值变化情况。

四、方案开发

相关介绍:KaiOS 新增APN信息字段的代码实现-CSDN博客

在 APN Editor中实现bearer显示

代码模块:gaia/apps/settings/js/panels/apn_editor/apn_editor.js

  1. /**
  2. * The apn editor module
  3. */
  4. 'use strict';
  5. define(function(require) { //eslint-disable-line
  6. const ApnEditorConst = require('panels/apn_editor_tct/apn_editor_const');
  7. const ApnEditorSession = require('panels/apn_editor_tct/apn_editor_session');
  8. const ApnUtils = require('modules/apn_tct/apn_utils');
  9. //以下三个常量都是从ApnEditorConst模块中导入的
  10. const { APN_PROPERTIES } = ApnEditorConst;
  11. const { APN_PROPERTY_DEFAULTS } = ApnEditorConst;
  12. const { VALUE_CONVERTERS } = ApnEditorConst;
  13. return function apnEditor(rootElement) {
  14. return new ApnEditor(rootElement);
  15. };
  16. });
将kaios中十进制的bearer转换同Android原始配置的bitmask

测试代码

  1. // 功能:将十进制bearer转换成1-20字符串(同Android)
  2. function bitmaskToString(aBearerBitmask) {
  3. if (aBearerBitmask == 0 || aBearerBitmask === undefined) {
  4. return 0;
  5. }
  6. let val = "";
  7. for (let i = 1; i < 20; i++) {
  8. if ((aBearerBitmask & (1 << (i - 1))) != 0) {
  9. val = val.concat(i + "|");
  10. }
  11. }
  12. return val;
  13. }
  14. //常量数组,定义rat
  15. const GECKO_RADIO_TECH = [
  16. null,
  17. "gprs",
  18. "edge",
  19. "umts",
  20. "is95a",
  21. "is95b",
  22. "1xrtt",
  23. "evdo0",
  24. "evdoa",
  25. "hsdpa",
  26. "hsupa",
  27. "hspa",
  28. "evdob",
  29. "ehrpd",
  30. "lte",
  31. "hspa+",
  32. "gsm",
  33. "tdscdma",
  34. "iwlan",
  35. "lte_ca",
  36. ];
  37. //将1-20的bitmask转换成对应的网络制式
  38. function bitmaskToRatString(aBitmask) {
  39. if (aBitmask == 0 || aBitmask === undefined) {
  40. return "unspecified";
  41. }
  42. let rat = "";
  43. let splitResult = aBitmask.split("|");
  44. console.log('splitResult = '+ splitResult);
  45. rat = splitResult.map(x => GECKO_RADIO_TECH[x]).join(",").slice(0,-1);
  46. //slice(startIndex,endIndex) 用于去掉最后一个逗号
  47. return rat;
  48. }
  49. // 测试代码
  50. let apnBearer = '312312'; //apn.json原始配置值
  51. let targetBearer; //1-20转换目标值
  52. let bearerString = '';
  53. if (apnBearer === undefined) {
  54. targetBearer = 0;
  55. } else {
  56. targetBearer = apnBearer;
  57. }
  58. bearerString = bitmaskToString(targetBearer);
  59. // 输出结果
  60. console.log('targetBearer = ' + targetBearer);
  61. console.log('bearerString = '+ bearerString);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/122450
推荐阅读
相关标签
  

闽ICP备14008679号