sec: RSIM access helper
[libsamsung-ipc.git] / include / sec.h
1 /*
2  * This file is part of libsamsung-ipc.
3  *
4  * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
5  * Copyright (C) 2011-2014 Paul Kocialkowski <contact@paulk.fr>
6  *
7  * libsamsung-ipc is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * libsamsung-ipc is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <samsung-ipc.h>
22
23 #ifndef __SAMSUNG_IPC_SEC_H__
24 #define __SAMSUNG_IPC_SEC_H__
25
26 /*
27  * Commands
28  */
29
30 #define IPC_SEC_PIN_STATUS                                      0x0501
31 #define IPC_SEC_PHONE_LOCK                                      0x0502
32 #define IPC_SEC_CHANGE_LOCKING_PW                               0x0503
33 #define IPC_SEC_SIM_LANG                                        0x0504
34 #define IPC_SEC_RSIM_ACCESS                                     0x0505
35 #define IPC_SEC_GSIM_ACCESS                                     0x0506
36 #define IPC_SEC_SIM_ICC_TYPE                                    0x0507
37 #define IPC_SEC_LOCK_INFOMATION                                 0x0508
38 #define IPC_SEC_IMS_AUTH                                        0x0509
39
40 /*
41  * Values
42  */
43
44 #define IPC_SEC_PIN_STATUS_READY                                0x00
45 #define IPC_SEC_PIN_STATUS_SIM_LOCK_REQUIRED                    0x01
46 #define IPC_SEC_PIN_STATUS_INSIDE_PF_ERROR                      0x02
47 #define IPC_SEC_PIN_STATUS_LOCK_SC                              0x03
48 #define IPC_SEC_PIN_STATUS_LOCK_FD                              0x04
49 #define IPC_SEC_PIN_STATUS_LOCK_PN                              0x05
50 #define IPC_SEC_PIN_STATUS_LOCK_PU                              0x06
51 #define IPC_SEC_PIN_STATUS_LOCK_PP                              0x07
52 #define IPC_SEC_PIN_STATUS_LOCK_PC                              0x08
53 #define IPC_SEC_PIN_STATUS_CARD_NOT_PRESENT                     0x80
54 #define IPC_SEC_PIN_STATUS_CARD_ERROR                           0x81
55 #define IPC_SEC_PIN_STATUS_INIT_COMPLETE                        0x82
56 #define IPC_SEC_PIN_STATUS_PB_INIT_COMPLETE                     0x83
57
58 #define IPC_SEC_FACILITY_LOCK_TYPE_SC_UNLOCKED                  0x00
59 #define IPC_SEC_FACILITY_LOCK_TYPE_SC_PIN1_REQ                  0x01
60 #define IPC_SEC_FACILITY_LOCK_TYPE_SC_PUK_REQ                   0x02
61 #define IPC_SEC_FACILITY_LOCK_TYPE_SC_CARD_BLOCKED              0x05
62
63 #define IPC_SEC_PIN_TYPE_PIN1                                   0x03
64 #define IPC_SEC_PIN_TYPE_PIN2                                   0x09
65
66 #define IPC_SEC_FACILITY_TYPE_SC                                0x03
67 #define IPC_SEC_FACILITY_TYPE_FD                                0x04
68 #define IPC_SEC_FACILITY_TYPE_PN                                0x05
69 #define IPC_SEC_FACILITY_TYPE_PU                                0x06
70 #define IPC_SEC_FACILITY_TYPE_PP                                0x07
71 #define IPC_SEC_FACILITY_TYPE_PC                                0x08
72
73 #define IPC_SEC_RSIM_COMMAND_READ_BINARY                        0xB0
74 #define IPC_SEC_RSIM_COMMAND_READ_RECORD                        0xB2
75 #define IPC_SEC_RSIM_COMMAND_GET_RESPONSE                       0xC0
76 #define IPC_SEC_RSIM_COMMAND_UPDATE_BINARY                      0xD6
77 #define IPC_SEC_RSIM_COMMAND_UPDATE_RECORD                      0xDC
78 #define IPC_SEC_RSIM_COMMAND_STATUS                             0xF2
79 #define IPC_SEC_RSIM_COMMAND_RETRIEVE_DATA                      0xCB
80 #define IPC_SEC_RSIM_COMMAND_SET_DATA                           0xDB
81
82 #define IPC_SEC_RSIM_FILE_STRUCTURE_TRANSPARENT                 0x83
83 #define IPC_SEC_RSIM_FILE_STRUCTURE_LINEAR_FIXED                0x00
84
85 #define IPC_SEC_SIM_CARD_TYPE_UNKNOWN                           0x00
86 #define IPC_SEC_SIM_CARD_TYPE_SIM                               0x01
87 #define IPC_SEC_SIM_CARD_TYPE_USIM                              0x02
88
89 /*
90  * Structures
91  */
92
93 struct ipc_sec_pin_status_response_data {
94     unsigned char status; // IPC_SEC_PIN_STATUS
95     unsigned char facility_lock; // IPC_SEC_FACILITY_LOCK_TYPE
96 } __attribute__((__packed__));
97
98 struct ipc_sec_pin_status_request_data {
99     unsigned char type; // IPC_SEC_PIN_TYPE
100     unsigned char pin1_length;
101     unsigned char pin2_length;
102     unsigned char pin1[8];
103     unsigned char pin2[8];
104 } __attribute__((__packed__));
105
106 struct ipc_sec_phone_lock_request_set_data {
107     unsigned char facility_type; // IPC_SEC_FACILITY_TYPE
108     unsigned char active;
109     unsigned char password_length;
110     unsigned char password[39];
111 }  __attribute__((__packed__));
112
113 struct ipc_sec_phone_lock_request_get_data {
114     unsigned char facility_type; // IPC_SEC_FACILITY_TYPE
115 }  __attribute__((__packed__));
116
117 struct ipc_sec_phone_lock_response_data {
118     unsigned char facility_type; // IPC_SEC_FACILITY_TYPE
119     unsigned char active;
120 } __attribute__((__packed__));
121
122 struct ipc_sec_change_locking_pw_data {
123     unsigned char facility_type; // IPC_SEC_FACILITY_TYPE
124     unsigned char password_old_length;
125     unsigned char password_new_length;
126     unsigned char password_old[39];
127     unsigned char password_new[39];
128 }  __attribute__((__packed__));
129
130 struct ipc_sec_rsim_access_request_header {
131     unsigned char command; // IPC_SEC_RSIM_COMMAND
132     unsigned short file_id;
133     unsigned char p1, p2, p3;
134 } __attribute__((__packed__));
135
136 struct ipc_sec_rsim_access_response_header {
137     unsigned char sw1, sw2;
138     unsigned char length;
139 } __attribute__((__packed__));
140
141 struct ipc_sec_rsim_access_usim_response_header {
142         unsigned char unknown1[3];
143     unsigned char offset;
144     unsigned char unknown2[2];
145         unsigned char file_structure; // IPC_SEC_RSIM_FILE_STRUCTURE
146         unsigned char length;
147 } __attribute__((__packed__));
148
149 struct ipc_sec_sim_icc_type_data {
150     unsigned char type; // IPC_SEC_SIM_CARD_TYPE
151 } __attribute__((__packed__));
152
153 struct ipc_sec_lock_infomation_request_data {
154     unsigned char magic;
155     unsigned char type; // IPC_SEC_PIN_TYPE
156 } __attribute__((__packed__));
157
158 struct ipc_sec_lock_infomation_response_data {
159     unsigned char unknown;
160     unsigned char type; // IPC_SEC_PIN_TYPE
161     unsigned char key;
162     unsigned char retry_count;
163 } __attribute__((__packed__));
164
165 /*
166  * Helpers
167  */
168
169 int ipc_sec_pin_status_setup(struct ipc_sec_pin_status_request_data *data,
170     unsigned char type, const char *pin1, const char *pin2);
171 int ipc_sec_phone_lock_request_set_setup(struct ipc_sec_phone_lock_request_set_data *data,
172     unsigned char facility_type, unsigned char active, const char *password);
173 int ipc_sec_change_locking_pw_setup(struct ipc_sec_change_locking_pw_data *data,
174     unsigned char facility_type, const char *password_old,
175     const char *password_new);
176 void *ipc_sec_rsim_access_setup(struct ipc_sec_rsim_access_request_header *header,
177     const void *sim_io_data, size_t sim_io_size);
178 int ipc_sec_lock_infomation_setup(struct ipc_sec_lock_infomation_request_data *data,
179     unsigned char type);
180
181 #endif
182
183 // vim:ts=4:sw=4:expandtab