xref: /freebsd/contrib/wpa/src/utils/pcsc_funcs.h (revision 9517e866259191fcd39434a97ad849a9b59b9b9f)
1 /*
2  * WPA Supplicant / PC/SC smartcard interface for USIM, GSM SIM
3  * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14 
15 #ifndef PCSC_FUNCS_H
16 #define PCSC_FUNCS_H
17 
18 /* GSM files
19  * File type in first octet:
20  * 3F = Master File
21  * 7F = Dedicated File
22  * 2F = Elementary File under the Master File
23  * 6F = Elementary File under a Dedicated File
24  */
25 #define SCARD_FILE_MF		0x3F00
26 #define SCARD_FILE_GSM_DF	0x7F20
27 #define SCARD_FILE_UMTS_DF	0x7F50
28 #define SCARD_FILE_GSM_EF_IMSI	0x6F07
29 #define SCARD_FILE_EF_DIR	0x2F00
30 #define SCARD_FILE_EF_ICCID	0x2FE2
31 #define SCARD_FILE_EF_CK	0x6FE1
32 #define SCARD_FILE_EF_IK	0x6FE2
33 
34 #define SCARD_CHV1_OFFSET	13
35 #define SCARD_CHV1_FLAG		0x80
36 
37 typedef enum {
38 	SCARD_GSM_SIM_ONLY,
39 	SCARD_USIM_ONLY,
40 	SCARD_TRY_BOTH
41 } scard_sim_type;
42 
43 
44 #ifdef PCSC_FUNCS
45 struct scard_data * scard_init(scard_sim_type sim_type);
46 void scard_deinit(struct scard_data *scard);
47 
48 int scard_set_pin(struct scard_data *scard, const char *pin);
49 int scard_get_imsi(struct scard_data *scard, char *imsi, size_t *len);
50 int scard_gsm_auth(struct scard_data *scard, const unsigned char *_rand,
51 		   unsigned char *sres, unsigned char *kc);
52 int scard_umts_auth(struct scard_data *scard, const unsigned char *_rand,
53 		    const unsigned char *autn,
54 		    unsigned char *res, size_t *res_len,
55 		    unsigned char *ik, unsigned char *ck, unsigned char *auts);
56 
57 #else /* PCSC_FUNCS */
58 
59 #define scard_init(s) NULL
60 #define scard_deinit(s) do { } while (0)
61 #define scard_set_pin(s, p) -1
62 #define scard_get_imsi(s, i, l) -1
63 #define scard_gsm_auth(s, r, s2, k) -1
64 #define scard_umts_auth(s, r, a, r2, rl, i, c, a2) -1
65 
66 #endif /* PCSC_FUNCS */
67 
68 #endif /* PCSC_FUNCS_H */
69