2 * BlueZ - Bluetooth protocol stack for Linux
4 * Copyright (C) 2010 Instituto Nokia de Tecnologia - INdT
5 * Copyright (C) 2010 ST-Ericsson SA
7 * Author: Marek Skowron <marek.skowron@tieto.com> for ST-Ericsson.
8 * Author: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #define SAP_VERSION 0x0101
31 /* Connection Status - SAP v1.1 section 5.2.2 */
34 SAP_STATUS_CONNECTION_FAILED = 0x01,
35 SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED = 0x02,
36 SAP_STATUS_MAX_MSG_SIZE_TOO_SMALL = 0x03,
37 SAP_STATUS_OK_ONGOING_CALL = 0x04
40 /* Disconnection Type - SAP v1.1 section 5.2.3 */
41 enum sap_disconnection_type {
42 SAP_DISCONNECTION_TYPE_GRACEFUL = 0x00,
43 SAP_DISCONNECTION_TYPE_IMMEDIATE = 0x01,
44 SAP_DISCONNECTION_TYPE_CLIENT = 0xFF
47 /* Result codes - SAP v1.1 section 5.2.4 */
50 SAP_RESULT_ERROR_NO_REASON = 0x01,
51 SAP_RESULT_ERROR_NOT_ACCESSIBLE = 0x02,
52 SAP_RESULT_ERROR_POWERED_OFF = 0x03,
53 SAP_RESULT_ERROR_CARD_REMOVED = 0x04,
54 SAP_RESULT_ERROR_POWERED_ON = 0x05,
55 SAP_RESULT_ERROR_NO_DATA = 0x06,
56 SAP_RESULT_NOT_SUPPORTED = 0x07
59 /* Status Change - SAP v1.1 section 5.2.8 */
60 enum sap_status_change {
61 SAP_STATUS_CHANGE_UNKNOWN_ERROR = 0x00,
62 SAP_STATUS_CHANGE_CARD_RESET = 0x01,
63 SAP_STATUS_CHANGE_CARD_NOT_ACCESSIBLE = 0x02,
64 SAP_STATUS_CHANGE_CARD_REMOVED = 0x03,
65 SAP_STATUS_CHANGE_CARD_INSERTED = 0x04,
66 SAP_STATUS_CHANGE_CARD_RECOVERED = 0x05
69 /* Message format - SAP v1.1 section 5.1 */
70 struct sap_parameter {
76 * Padding bytes 0-3 bytes
78 } __attribute__((packed));
84 struct sap_parameter param[0];
85 } __attribute__((packed));
87 #define SAP_BUF_SIZE 512
88 #define SAP_MSG_HEADER_SIZE 4
91 SAP_CONNECT_REQ = 0x00,
92 SAP_CONNECT_RESP = 0x01,
93 SAP_DISCONNECT_REQ = 0x02,
94 SAP_DISCONNECT_RESP = 0x03,
95 SAP_DISCONNECT_IND = 0x04,
96 SAP_TRANSFER_APDU_REQ = 0x05,
97 SAP_TRANSFER_APDU_RESP = 0x06,
98 SAP_TRANSFER_ATR_REQ = 0x07,
99 SAP_TRANSFER_ATR_RESP = 0x08,
100 SAP_POWER_SIM_OFF_REQ = 0x09,
101 SAP_POWER_SIM_OFF_RESP = 0x0A,
102 SAP_POWER_SIM_ON_REQ = 0x0B,
103 SAP_POWER_SIM_ON_RESP = 0x0C,
104 SAP_RESET_SIM_REQ = 0x0D,
105 SAP_RESET_SIM_RESP = 0x0E,
106 SAP_TRANSFER_CARD_READER_STATUS_REQ = 0x0F,
107 SAP_TRANSFER_CARD_READER_STATUS_RESP = 0x10,
108 SAP_STATUS_IND = 0x11,
109 SAP_ERROR_RESP = 0x12,
110 SAP_SET_TRANSPORT_PROTOCOL_REQ = 0x13,
111 SAP_SET_TRANSPORT_PROTOCOL_RESP = 0x14
114 /* Parameters Ids - SAP 1.1 section 5.2 */
116 SAP_PARAM_ID_MAX_MSG_SIZE = 0x00,
117 SAP_PARAM_ID_CONN_STATUS = 0x01,
118 SAP_PARAM_ID_RESULT_CODE = 0x02,
119 SAP_PARAM_ID_DISCONNECT_IND = 0x03,
120 SAP_PARAM_ID_COMMAND_APDU = 0x04,
121 SAP_PARAM_ID_COMMAND_APDU7816 = 0x10,
122 SAP_PARAM_ID_RESPONSE_APDU = 0x05,
123 SAP_PARAM_ID_ATR = 0x06,
124 SAP_PARAM_ID_CARD_READER_STATUS = 0x07,
125 SAP_PARAM_ID_STATUS_CHANGE = 0x08,
126 SAP_PARAM_ID_TRANSPORT_PROTOCOL = 0x09
129 #define SAP_PARAM_ID_MAX_MSG_SIZE_LEN 0x02
130 #define SAP_PARAM_ID_CONN_STATUS_LEN 0x01
131 #define SAP_PARAM_ID_RESULT_CODE_LEN 0x01
132 #define SAP_PARAM_ID_DISCONNECT_IND_LEN 0x01
133 #define SAP_PARAM_ID_CARD_READER_STATUS_LEN 0x01
134 #define SAP_PARAM_ID_STATUS_CHANGE_LEN 0x01
135 #define SAP_PARAM_ID_TRANSPORT_PROTO_LEN 0x01
137 /* Transport Protocol - SAP v1.1 section 5.2.9 */
138 enum sap_transport_protocol {
139 SAP_TRANSPORT_PROTOCOL_T0 = 0x00,
140 SAP_TRANSPORT_PROTOCOL_T1 = 0x01
143 /*SAP driver init and exit routines. Implemented by sap-*.c */
147 /* SAP requests implemented by sap-*.c */
148 void sap_connect_req(void *sap_device, uint16_t maxmsgsize);
149 void sap_disconnect_req(void *sap_device, uint8_t linkloss);
150 void sap_transfer_apdu_req(void *sap_device, struct sap_parameter *param);
151 void sap_transfer_atr_req(void *sap_device);
152 void sap_power_sim_off_req(void *sap_device);
153 void sap_power_sim_on_req(void *sap_device);
154 void sap_reset_sim_req(void *sap_device);
155 void sap_transfer_card_reader_status_req(void *sap_device);
156 void sap_set_transport_protocol_req(void *sap_device,
157 struct sap_parameter *param);
159 /*SAP responses to SAP requests. Implemented by server.c */
160 int sap_connect_rsp(void *sap_device, uint8_t status, uint16_t maxmsgsize);
161 int sap_disconnect_rsp(void *sap_device);
162 int sap_transfer_apdu_rsp(void *sap_device, uint8_t result,
163 uint8_t *sap_apdu_resp, uint16_t length);
164 int sap_transfer_atr_rsp(void *sap_device, uint8_t result,
165 uint8_t *sap_atr, uint16_t length);
166 int sap_power_sim_off_rsp(void *sap_device, uint8_t result);
167 int sap_power_sim_on_rsp(void *sap_device, uint8_t result);
168 int sap_reset_sim_rsp(void *sap_device, uint8_t result);
169 int sap_transfer_card_reader_status_rsp(void *sap_device, uint8_t result,
171 int sap_error_rsp(void *sap_device);
172 int sap_transport_protocol_rsp(void *sap_device, uint8_t result);
174 /* Event indication. Implemented by server.c*/
175 int sap_status_ind(void *sap_device, uint8_t status_change);
176 int sap_disconnect_ind(void *sap_device, uint8_t disc_type);