SAT(sim application toolkit),也可以称为STK ,是一种增值服务,运营商利用SAT为用户提供更加丰富多彩的增值服务。
在传统功能里,手机是主导,SIM卡是从属,手机主动去读取SIM卡里的文件;但是在SAT功能里,SIM卡是主导,手机是从属,SIM卡主动要求手机做一些事情,例如显示欢迎语,显示SAT菜单之类的;或者要求手机把SIM卡感兴趣的事情告知SIM卡。
因此,定义了一个名为Fetch的命令。当手机给SIM卡发送普通命令(如Status等)的时候,SIM卡的返回值可以是:我有一条主动式命令要发出(值为91XX)。当手机收到这个返回值时候,就立即发送Fetch命令给SIM卡,从而在SIM卡的返回值中获取到这条主动式命令。在手机执行完命令之后,需要发送返回值给SIM卡。如果没有后续命令,SIM卡返回结束消息(值为9000)如下图所示:
从上图还可以看出,手机对命令的执行结果,通过Terminal Response发送给SIM卡。
Terminal Response可以是:
• 成功
• 失败,有临时性问题。如手机正在打电话,有些命令暂时不能执行。
• 失败,有永久性问题。如命令无法解析,命令超出手机执行能力,或者和网络相关的命令被网络拒绝等。
命令的Tag在协议11.14的第13.1和13.2章节中定义,常用的有:
• D0:Proactive SIM command tag
• D3:Menu Selection tag
• D6:Event download tag
命令TLV结构的Value部分,由多个内容TLV组成。
问题总结一、在手机开机时,会弹出欢迎界面,这个欢迎界面就是STK的主动式命令“Display Text”发起的。 命令:
D0308103012101820281028D25085C0A656C768475286237FF0C6B228FCE60A84F7F75284E2D56FD8054901A4E1A52A1FF01
D0: TAG,表示主动式命令
30: LENGTH,0x30=48,表示命令的VALUE部分长度为48 byte。
以下是命令内容
81: Command details tag
03: Command details length
01: cmd.number
21: cmd.type -> DISPLAY TEXT
01: cmd.qual -> high priority;
clear message after a delay;
82: Device identity tag
02: Device identity length
81: Devices.source -> SIM
02: Devices.dest -> Display
8D: Text string tag(见TLV TAG里的TEXT_STRING(0x0d))
25: Text string length
08: Data coding scheme,表示字串使用UCS2编码
5C0A: UCS2[0]: 尊
656C: UCS2[1]: 敬
7684: UCS2[2]: 的
7528: UCS2[3]: 用
6237: UCS2[4]: 户
FF0C: UCS2[5]: ,
6B22: UCS2[6]: 欢
8FCE: UCS2[7]: 迎
60A8: UCS2[8]: 您
4F7F: UCS2[9]: 使
7528: UCS2[10]: 用
4E2D: UCS2[11]: 中
56FD: UCS2[12]: 国
8054: UCS2[13]: 联
901A: UCS2[14]: 通
4E1A: UCS2[15]: 业
52A1: UCS2[16]: 务
FF01: UCS2[17]: !
执行结果就是:手机立即显示“尊敬的用户,欢迎您使用中国联通业务!”
问题总结二:TERMINAL RESPONSE 解析
处理在CommandParamsFactory,和CatService里
if (cmdDet.compRequired) {
tag |= 0x80;
}
#TERMINAL RESPONSE
DEV_ID_KEYPAD = 0x01;
DEV_ID_DISPLAY = 0x02;
DEV_ID_UICC = 0x81;
DEV_ID_TERMINAL = 0x82;
DEV_ID_NETWORK = 0x83;
public enum ComprehensionTlvTag {
COMMAND_DETAILS(0x01),
DEVICE_IDENTITIES(0x02),
RESULT(0x03),
DURATION(0x04),
ALPHA_ID(0x05),
ADDRESS(0x06),
USSD_STRING(0x0a),
SMS_TPDU(0x0b),
TEXT_STRING(0x0d),
TONE(0x0e),
ITEM(0x0f),
ITEM_ID(0x10),
RESPONSE_LENGTH(0x11),
FILE_LIST(0x12),
HELP_REQUEST(0x15),
DEFAULT_TEXT(0x17),
EVENT_LIST(0x19),
ICON_ID(0x1e),
ITEM_ICON_ID_LIST(0x1f),
IMMEDIATE_RESPONSE(0x2b),
LANGUAGE(0x2d),
URL(0x31),
BROWSER_TERMINATION_CAUSE(0x34),
TEXT_ATTRIBUTE(0x50),
CAUSE(0x1a),
TRANSACTION_ID(0x1c),
BEARER_DESCRIPTION(0x35),
CHANNEL_DATA(0x36),
CHANNEL_DATA_LENGTH(0x37),
CHANNEL_STATUS(0x38),
BUFFER_SIZE(0x39),
SIM_ME_INTERFACE_TRANSPORT_LEVEL(0x3C),
OTHER_ADDRESS(0x3E),
DNS_SERVER_ADDRESS(0x40),
NETWORK_ACCESS_NAME(0x47),
NEXT_ACTION_INDICATOR(0x18),
DATE_TIME_AND_TIMEZONE(0x26),
BATTERY_STATE(0x63),
ACTIVATE_DESCRIPTOR(0x7B);
810301250082028281830100
81[Tlv COMMAND_DETAILS]03[length]01[commandNumber]25[typeOfCommand]00[commandQualifier]
82[Tlv DEVICE_IDENTITIES]02[length]82[source device id]81[destination device id]
83[Tlv RESULT]01[length]00[resultCode]
问题总结三:点击 STK Icon 没反应
//开机或 refresh 后,sim 上报的 set up menu 指令,CatService 收到 set up menu.
12-31 18:08:01.844194 1490 1490 D CAT : CatService: handleMessage[10]
12-31 18:08:01.844357 1490 1490 D CAT : CatService: SET_UP_MENU
12-31 18:08:01.845522 1490 1490 D CAT : CAT: mSetUpMenuFromMD: true
12-31 18:08:01.846026 1490 1490 D CAT : CatService: SS-sendTR: command type is 37
12-31 18:08:01.846284 1490 1490 D CAT : CatService: encodeOptionalTags() Unsupported Cmd details=CmdDetails: compRequired=true commandNumber=1 typeOfCommand=37 commandQualifier=0
12-31 18:08:01.846435 1490 1490 D CAT : CatService: TERMINAL RESPONSE: 810301250082028281830100
12-31 18:08:01.849209 1490 1490 D CAT : CatService: Sending CmdMsg: com.android.internal.telephony.cat.CatCmdMessage@bf8cac0 on slotid:0
//catservice 发广播
12-31 18:08:01.851211 846 1664 V ActivityManager: Broadcast: Intent { act=android.intent.action.stk.command flg=0x10 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{bdd92c0 1490:com.android.phone/1001}
//54秒后,STK AP 才收到广播。
12-31 18:08:55.672267 1490 1490 D ActivityThread: BDC-Calling onReceive: intent=Intent { act=android.intent.action.stk.command flg=0x10 cmp=com.android.stk/.StkCmdReceiver (has extras) }, receiver=com.android.stk.StkCmdReceiver@db84bac
12-31 18:08:55.685323 1490 1490 D ActivityThread: BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=android.intent.action.stk.command flg=0x10 cmp=com.android.stk/.StkCmdReceiver (has extras) } packageName=com.android.stk resultCode=-1 resultData=null resultExtras=null}
12-31 18:08:55.690877 1490 1490 D CAT : StkAppService: StkAppService onStart sim id: 0, op: 1, Bundle[{SLOT_ID=0, cmd message=com.android.internal.telephony.cat.CatCmdMessage@4dff87b, op=1}]
12-31 18:08:55.690980 1490 1490 D CAT : StkAppService: StkAppService onStart mPhone: Handler (com.android.internal.telephony.PhoneProxy) {41d633d}, mPhoneStateChangeReg: true
12-31 18:08:55.691419 1490 2387 D CAT : StkAppInstaller: Init thread
12-31 18:08:55.691523 1490 2387 D CAT : StkAppService: handleMessage opcode[1], sim id[0]
12-31 18:08:55.691643 1490 2387 D CAT : StkAppService: cmdName[SET_UP_MENU]
问题总结三:STK上报子级菜单
D0398103012400820281828F0E0180727960E0793C53058BA28D2D8F0E0280727960E0793C530590008BA28F0E0380727960E0793C53054ECB7ECD
D039
8103012400[36上报子级菜单]
82028182
8F0E[length28]
0180
727960E0793C53058BA28D2D
8F0E[length28]
0280
727960E0793C530590008BA2
8F0E[length28]
0380
727960E0793C53054ECB7ECD
问题总结四:STK上报一级菜单
D081 BA
8103 012500[37上报一级菜单]
8202 8182
850F 80005500530049004D53615E947528
8F0A 248073AF740365F662A5
8F0A 258053C280036D88606F
8F0A 37807CBE54C163A88350
8F0A 628059296C14988462A5
8F0A 6480822A73ED67E58BE2
8F0A 668051FA884C63075357
8F0A 68804F53575B5FEB8BAF
8F0C A28065B095FB65E9665A62A5
8F0A A480624B673A97F34E50
8F0A A680624B673A96058BFB
8F0A A880624B673A90AE7BB1
8F0A AA8077ED4FE152A97406
8F0C AC80624B673A84254E1A5385