summaryrefslogtreecommitdiffstats
path: root/src/isi-simauth.c
blob: 779b7fe1f6e4b6b912527e420cf9cd8da38eefa4 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* isi-simauth.c
 * Dissector for ISI's SIM authentication resource
 * Copyright 2010, Sebastian Reichel <sre@ring0.de>
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <glib.h>
#include <epan/prefs.h>
#include <epan/packet.h>

#include "packet-isi.h"
#include "isi-simauth.h"

static const value_string isi_sim_auth_id[] = {
	{0x01, "SIM_AUTH_PROTECTED_REQ"},
	{0x02, "SIM_AUTH_PROTECTED_RESP"},
	{0x04, "SIM_AUTH_UPDATE_REQ"},
	{0x05, "SIM_AUTH_UPDATE_SUCCESS_RESP"},
	{0x06, "SIM_AUTH_UPDATE_FAIL_RESP"},
	{0x07, "SIM_AUTH_REQ"},
	{0x08, "SIM_AUTH_SUCCESS_RESP"},
	{0x09, "SIM_AUTH_FAIL_RESP"},
	{0x10, "SIM_AUTH_STATUS_IND"},
	{0x11, "SIM_AUTH_STATUS_REQ"},
	{0x12, "SIM_AUTH_STATUS_RESP"},
	{0x00, NULL }
};

static const value_string isi_sim_auth_pw_type[] = {
	{0x02, "SIM_AUTH_PIN"},
	{0x03, "SIM_AUTH_PUK"},
	{0x63, "SIM_AUTH_NONE"},
	{0x00, NULL}
};

static const value_string isi_sim_auth_protection_req[] = {
	{0x00, "SIM_AUTH_PROTECTION_DISABLE"},
	{0x01, "SIM_AUTH_PROTECTION_ENABLE"},
	{0x04, "SIM_AUTH_PROTECTION_STATUS"},
	{0x00, NULL}
};

static const value_string isi_sim_auth_resp[] = {
	{0x02, "SIM_AUTH_STATUS_RESP_NEED_PIN"},
	{0x03, "SIM_AUTH_STATUS_RESP_NEED_PUK"},
	{0x05, "SIM_AUTH_STATUS_RESP_RUNNING"},
	{0x07, "SIM_AUTH_STATUS_RESP_INIT"},
	{0x00, NULL}
};

static const value_string isi_sim_auth_indication[] = {
	{0x01, "SIM_AUTH_NEED_AUTH"},
	{0x02, "SIM_AUTH_NEED_NO_AUTH"},
	{0x03, "SIM_AUTH_VALID"},
	{0x04, "SIM_AUTH_INVALID"},
	{0x05, "SIM_AUTH_AUTHORIZED"},
	{0x06, "SIM_AUTH_IND_CONFIG"},
	{0x00, NULL}
};

static const value_string isi_sim_auth_indication_cfg[] = {
	{0x0B, "SIM_AUTH_PIN_PROTECTED_DISABLE"},
	{0x0C, "SIM_AUTH_PIN_PROTECTED_ENABLE"},
	{0x00, NULL}
};

static dissector_handle_t isi_sim_auth_handle;
static void dissect_isi_sim_auth(tvbuff_t *tvb, packet_info *pinfo, proto_item *tree);

static guint32 hf_isi_sim_auth_cmd = -1;
static guint32 hf_isi_sim_auth_status_rsp = -1;
static guint32 hf_isi_sim_auth_protection_req = -1;
static guint32 hf_isi_sim_auth_protection_rsp = -1;
static guint32 hf_isi_sim_auth_pin = -1;
static guint32 hf_isi_sim_auth_puk = -1;
static guint32 hf_isi_sim_auth_new_pin = -1;
static guint32 hf_isi_sim_auth_pw_type = -1;
static guint32 hf_isi_sim_auth_indication = -1;
static guint32 hf_isi_sim_auth_indication_cfg = -1;

void proto_reg_handoff_isi_sim_auth(void) {
	static gboolean initialized=FALSE;

	if (!initialized) {
		isi_sim_auth_handle = create_dissector_handle(dissect_isi_sim_auth, proto_isi);
		dissector_add("isi.resource", 0x08, isi_sim_auth_handle);
	}
}

void proto_register_isi_sim_auth(void) {
	static hf_register_info hf[] = {
		{ &hf_isi_sim_auth_cmd,
		  { "Command", "isi.sim.auth.cmd", FT_UINT8, BASE_HEX, isi_sim_auth_id, 0x0, "Command", HFILL }},
		{ &hf_isi_sim_auth_pw_type,
		  { "Password Type", "isi.sim.auth.type", FT_UINT8, BASE_HEX, isi_sim_auth_pw_type, 0x0, "Password Type", HFILL }},
		{ &hf_isi_sim_auth_pin,
		  { "PIN", "isi.sim.auth.pin", FT_STRING, BASE_NONE, NULL, 0x0, "PIN", HFILL }},
		{ &hf_isi_sim_auth_puk,
		  { "PUK", "isi.sim.auth.puk", FT_STRING, BASE_NONE, NULL, 0x0, "PUK", HFILL }},
		{ &hf_isi_sim_auth_new_pin,
		  { "New PIN", "isi.sim.auth.new_pin", FT_STRING, BASE_NONE, NULL, 0x0, "New PIN", HFILL }},
		{ &hf_isi_sim_auth_protection_req,
		  { "Protection Request", "isi.sim.auth.request.protection", FT_UINT8, BASE_HEX, isi_sim_auth_protection_req, 0x0, "Protection Request", HFILL }},
		{ &hf_isi_sim_auth_protection_rsp,
		  { "Protection Response", "isi.sim.auth.response.protection", FT_BOOLEAN, BASE_HEX, NULL, 0x0, "Protection Response", HFILL }},
		{ &hf_isi_sim_auth_status_rsp,
		  { "Status Response", "isi.sim.auth.response.status", FT_UINT8, BASE_HEX, isi_sim_auth_resp, 0x0, "Status Response", HFILL }},
		{ &hf_isi_sim_auth_indication,
		  { "Indication", "isi.sim.auth.indication", FT_UINT8, BASE_HEX, isi_sim_auth_indication, 0x0, "Indication", HFILL }},
		{ &hf_isi_sim_auth_indication_cfg,
		  { "Configuration", "isi.sim.auth.cfg", FT_UINT8, BASE_HEX, isi_sim_auth_indication_cfg, 0x0, "Configuration", HFILL }}
	};

	proto_register_field_array(proto_isi, hf, array_length(hf));
	register_dissector("isi.sim.auth", dissect_isi_sim_auth, proto_isi);
}

static void dissect_isi_sim_auth(tvbuff_t *tvb, packet_info *pinfo, proto_item *isitree) {
	proto_item *item = NULL;
	proto_tree *tree = NULL;
	guint8 cmd, code;

	if(isitree) {
		item = proto_tree_add_text(isitree, tvb, 0, -1, "Payload");
		tree = proto_item_add_subtree(item, ett_isi_msg);

		proto_tree_add_item(tree, hf_isi_sim_auth_cmd, tvb, 0, 1, FALSE);
		cmd = tvb_get_guint8(tvb, 0);

		switch(cmd) {
			case 0x01: // SIM_AUTH_PROTECTED_REQ
				proto_tree_add_item(tree, hf_isi_sim_auth_protection_req, tvb, 2, 1, FALSE);
				cmd = tvb_get_guint8(tvb, 2);
				switch(cmd) {
					case 0x00: // DISABLE
						proto_tree_add_item(tree, hf_isi_sim_auth_pin, tvb, 3, -1, FALSE);
						col_set_str(pinfo->cinfo, COL_INFO, "disable SIM startup protection");
						break;
					case 0x01: // ENABLE
						proto_tree_add_item(tree, hf_isi_sim_auth_pin, tvb, 3, -1, FALSE);
						col_set_str(pinfo->cinfo, COL_INFO, "enable SIM startup protection");
						break;
					case 0x04: // STATUS
						col_set_str(pinfo->cinfo, COL_INFO, "get SIM startup protection status");
						break;
					default:
						col_set_str(pinfo->cinfo, COL_INFO, "unknown SIM startup protection packet");
						break;
				}
				break;
			case 0x02: // SIM_AUTH_PROTECTED_RESP
				proto_tree_add_item(tree, hf_isi_sim_auth_protection_rsp, tvb, 1, 1, FALSE);
				if(tvb_get_guint8(tvb, 1))
					col_set_str(pinfo->cinfo, COL_INFO, "SIM startup protection enabled");
				else
					col_set_str(pinfo->cinfo, COL_INFO, "SIM startup protection disabled");
				break;
			case 0x04: // SIM_AUTH_UPDATE_REQ
				proto_tree_add_item(tree, hf_isi_sim_auth_pw_type, tvb, 1, 1, FALSE);
				code = tvb_get_guint8(tvb, 1);
				switch(code) {
					case 0x02: // PIN
						col_set_str(pinfo->cinfo, COL_INFO, "update SIM PIN");
						proto_tree_add_item(tree, hf_isi_sim_auth_pin, tvb, 2, 11, FALSE);
						proto_tree_add_item(tree, hf_isi_sim_auth_new_pin, tvb, 13, 11, FALSE);
						break;
					case 0x03: // PUK
						col_set_str(pinfo->cinfo, COL_INFO, "update SIM PUK");
						break;
					default:
						col_set_str(pinfo->cinfo, COL_INFO, "unknown SIM Authentication update request");
						break;
				}
				break;
			case 0x05: // SIM_AUTH_UPDATE_SUCCESS_RESP
				col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication update successful");
				break;
			case 0x06: // SIM_AUTH_UPDATE_FAIL_RESP
				col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication update failed");
				break;
			case 0x07: // SIM_AUTH_REQ
				proto_tree_add_item(tree, hf_isi_sim_auth_pw_type, tvb, 1, 1, FALSE);
				code = tvb_get_guint8(tvb, 1);
				switch(code) {
					case 0x02: // PIN
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication with PIN");
						proto_tree_add_item(tree, hf_isi_sim_auth_pin, tvb, 2, 11, FALSE);
						break;
					case 0x03: // PUK
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication with PUK");
						proto_tree_add_item(tree, hf_isi_sim_auth_puk, tvb, 2, 11, FALSE);
						proto_tree_add_item(tree, hf_isi_sim_auth_new_pin, tvb, 13, 11, FALSE);
						break;
					default:
						col_set_str(pinfo->cinfo, COL_INFO, "unknown SIM Authentication request");
						break;
				}
				break;
			case 0x08: // SIM_AUTH_SUCCESS_RESP
				col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication successful");
				break;
			case 0x09: // SIM_AUTH_FAIL_RESP
				col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication failed");
				break;
			case 0x10: // SIM_AUTH_STATUS_IND
				proto_tree_add_item(tree, hf_isi_sim_auth_indication, tvb, 1, 1, FALSE);
				code = tvb_get_guint8(tvb, 1);
				proto_tree_add_item(tree, hf_isi_sim_auth_pw_type, tvb, 2, 1, FALSE);
				switch(code) {
					case 0x01:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication indication: Authentication needed");
						break;
					case 0x02:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication indication: No Authentication needed");
						break;
					case 0x03:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication indication: Authentication valid");
						break;
					case 0x04:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication indication: Authentication invalid");
						break;
					case 0x05:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication indication: Authorized");
						break;
					case 0x06:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication indication: Config");
						proto_tree_add_item(tree, hf_isi_sim_auth_indication_cfg, tvb, 3, 1, FALSE);
						break;
					default:
						col_set_str(pinfo->cinfo, COL_INFO, "unknown SIM Authentication indication");
						break;
				}
				break;
			case 0x11: // SIM_AUTH_STATUS_REQ
				col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication status request");
				break;
			case 0x12: // SIM_AUTH_STATUS_RESP
				proto_tree_add_item(tree, hf_isi_sim_auth_status_rsp, tvb, 1, 1, FALSE);
				code = tvb_get_guint8(tvb, 1);
				switch(code) {
					case 0x02:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication status: need PIN");
						break;
					case 0x03:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication status: need PUK");
						break;
					case 0x05:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication status: running");
						break;
					case 0x07:
						col_set_str(pinfo->cinfo, COL_INFO, "SIM Authentication status: initializing");
						break;
					default:
						col_set_str(pinfo->cinfo, COL_INFO, "unknown SIM Authentication status response packet");
						break;
				}
				break;

			case 0xF0: /* COMMON_MESSAGE */
				dissect_isi_common("Security", tvb, pinfo, tree);
				break;

			default:
				col_set_str(pinfo->cinfo, COL_INFO, "unknown SIM Authentication packet");
				break;
		}
	}
}