summaryrefslogtreecommitdiffstats
path: root/sat.c
blob: 7dce03ab1fe4d2bb305d4d6763bd9c27fbd85180 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#define LOG_TAG "RIL-SAT"
#include <utils/Log.h>

#include "samsung-ril.h"
#include "util.h"

extern const struct RIL_Env *rilenv;
extern struct radio_state radio;
extern struct ipc_client *ipc_client;

/**
 * In: IPC_SAT_PROACTIVE_CMD
 *   STK proactive command
 *
 * Out: RIL_UNSOL_STK_PROACTIVE_COMMAND
 */
void respondSatProactiveCmdIndi(struct ipc_message_info *request)
{
	int data_len = (request->length-2);
	char *hexdata;

	hexdata = (char*)malloc(data_len*2+1);

	bin2hex((unsigned char*)request->data+2, data_len, hexdata);

	RIL_onUnsolicitedResponse(RIL_UNSOL_STK_PROACTIVE_COMMAND, hexdata, sizeof(char*));

	free(hexdata);
}

/**
 * In: IPC_SAT_PROACTIVE_CMD RESP
 *   STK proactive command
 *
 * Out: RIL_UNSOL_STK_SESSION_END
 */
void respondSatProactiveCmdResp(struct ipc_message_info *request)
{
	unsigned char sw1, sw2;

	sw1 = ((unsigned char*)request->data)[0];
	sw2 = ((unsigned char*)request->data)[1];

	if(sw1 == 0x90 && sw2 == 0x00) {
		RIL_onUnsolicitedResponse(RIL_UNSOL_STK_SESSION_END, NULL, 0);
	} else {
		LOGE("%s: unhandled response sw1=%02x sw2=%02x", __FUNCTION__, sw1, sw2);
	}
}

/**
 * Proactive command indi/resp helper function
 */
void respondSatProactiveCmd(struct ipc_message_info *request)
{
	if(request->type == IPC_TYPE_INDI) {
		respondSatProactiveCmdIndi(request);
	} else if(request->type == IPC_TYPE_RESP) {
		respondSatProactiveCmdResp(request);
	} else {
		LOGE("%s: unhandled proactive command response type %d", __FUNCTION__, request->type);
	}
}

/**
 * In: RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE
 *   Requests to send a terminal response to SIM for a received
 *   proactive command
 *
 * Out: IPC_SAT_PROACTIVE_CMD GET
 */
void requestSatSendTerminalResponse(RIL_Token t, void *data, size_t datalen)
{
	unsigned char buf[264];
	int len = (strlen(data) / 2);

	if(len > 255) {
		LOGE("%s: data exceeds maximum length", __FUNCTION__);
		RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
	}

	memset(buf, 0, sizeof(buf));

	buf[0] = len;
	hex2bin(data, strlen(data), &buf[1]);

	ipc_client_send(ipc_client, IPC_SAT_PROACTIVE_CMD, IPC_TYPE_GET, buf, sizeof(buf), getRequestId(t));

	RIL_onRequestComplete(t, RIL_E_SUCCESS, buf, sizeof(char*));
}

/**
 * In: RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND
 *   Requests to send a SAT/USAT envelope command to SIM.
 *   The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111
 *
 * Out: IPC_SAT_ENVELOPE_CMD EXEC
 */
void requestSatSendEnvelopeCommand(RIL_Token t, void *data, size_t datalen)
{
	unsigned char buf[264];
	int len = (strlen(data) / 2);

	if(len > 255) {
		LOGE("%s: data exceeds maximum length", __FUNCTION__);
		RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
	}

	memset(buf, 0, sizeof(buf));

	buf[0] = len;
	hex2bin(data, strlen(data), &buf[1]);

	ipc_client_send(ipc_client, IPC_SAT_ENVELOPE_CMD, IPC_TYPE_EXEC, buf, sizeof(buf), getRequestId(t));
}

/**
 * In: IPC_SAT_ENVELOPE_CMD EXEC
 *
 * Out: RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND
 *   Requests to send a SAT/USAT envelope command to SIM.
 *   The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111
 */
void respondSatEnvelopeCmd(struct ipc_message_info *request)
{
	int data_len = (request->length-2);
	char *hexdata;

	hexdata = (char*)malloc(data_len*2+1);

	bin2hex((unsigned char*)request->data+2, data_len, hexdata);

	RIL_onRequestComplete(getToken(request->aseq), RIL_E_SUCCESS, hexdata, sizeof(char*));

	free(hexdata);
}