1 /*--------------------------------------------------------------------------
2 Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 --------------------------------------------------------------------------*/
29 
30 #ifndef EAP_PROXY_QMI_H
31 #define EAP_PROXY_QMI_H
32 
33 
34 #include "eap_i.h"
35 #include "eap_config.h"
36 #include "eloop.h"
37 #include "eapol_supp/eapol_supp_sm.h"
38 #include "user_identity_module_v01.h"
39 
40 /*msec Response Timeout*/
41 #define QMI_RESP_TIME_OUT 2000
42 #define EAP_PROXY_KEYING_DATA_LEN 64
43 
44 #ifdef CONFIG_EAP_PROXY_DUAL_SIM
45 #define MAX_NO_OF_SIM_SUPPORTED 2
46 #else
47 #define MAX_NO_OF_SIM_SUPPORTED 1
48 #endif /* CONFIG_EAP_PROXY_DUAL_SIM */
49 
50 typedef enum {
51         QMI_STATE_IDLE = 0x00,
52         QMI_STATE_RESP_PENDING  = 0x01,
53         QMI_STATE_RESP_RECEIVED = 0x02,
54         QMI_STATE_RESP_TIME_OUT = 0x03
55 } qmi_state_e;
56 
57 typedef enum {
58         EAP_PROXY_QMI_SRVC_NO_RESULT,
59         EAP_PROXY_QMI_SRVC_SUCCESS,
60         EAP_PROXY_QMI_SRVC_FAILURE
61 } eap_proxy_qmi_srv_result;
62 
63 /* should match the EAP_state  of eap_i.h */
64 typedef enum {
65         EAP_PROXY_INITIALIZE, EAP_PROXY_DISABLED, EAP_PROXY_IDLE, EAP_PROXY_RECEIVED,
66         EAP_PROXY_GET_METHOD, EAP_PROXY_METHOD, EAP_PROXY_SEND_RESPONSE,
67         EAP_PROXY_DISCARD, EAP_PROXY_IDENTITY, EAP_PROXY_NOTIFICATION,
68         EAP_PROXY_RETRANSMIT,
69         EAP_PROXY_AUTH_SUCCESS,  EAP_PROXY_AUTH_FAILURE
70 } eap_proxy_state;
71 
72 
73 enum eap_proxy_status {
74         EAP_PROXY_FAILURE = 0x00,
75         EAP_PROXY_SUCCESS
76 };
77 
78 typedef enum {
79         EAP_IDENTITY_ANNONYMOUS = 0x00,
80         EAP_IDENTITY_IMSI_RAW  = 0x02,
81         EAP_IDENTITY_IMSI_3GPP_REALM = 0x03,
82         EAP_IDENTITY_IMSI_REALM = 0x04,
83         EAP_IDENTITY_CFG_RAW = 0x05,
84         EAP_IDENTITY_CFG_3GPP_REALM = 0x06,
85         EAP_IDENTITY_CFG_REALM = 0x07,
86 } eap_identity_format_e;
87 
88 typedef union
89 {
90         struct
91         {
92                 void *resp_data; /* Pointer to the Response Packet*/
93                 unsigned long length;     /*Length of the Response Packet*/
94         }eap_send_pkt_resp;
95 
96 }qmi_eap_sync_rsp_data_type;
97 
98 typedef struct {
99         uim_card_state_enum_v01                      card_state;
100         uim_card_error_code_enum_v01                 card_error_code;
101         u8                                           app_state;
102         u8                                           app_type;
103 } wpa_uim_card_info_type;
104 
105 typedef struct {
106         int                                   card_ready_idx;
107         wpa_uim_card_info_type                card_info[QMI_UIM_CARDS_MAX_V01];
108         qmi_client_type                       qmi_uim_svc_client_ptr;
109         int                                   qmi_msg_lib_handle;
110 } wpa_uim_struct_type;
111 
112 
113 struct eap_proxy_sm {
114         qmi_client_type qmi_auth_svc_client_ptr[MAX_NO_OF_SIM_SUPPORTED];
115         qmi_state_e qmi_state;
116         eap_proxy_qmi_srv_result srvc_result;
117         qmi_eap_sync_rsp_data_type qmi_resp_data;
118         eap_proxy_state  proxy_state;
119         Boolean iskey_valid;
120         u8 *key;
121         Boolean is_state_changed;
122         void *ctx;
123         void *msg_ctx;
124         struct eapol_callbacks *eapol_cb;
125         u8 *eapReqData;
126         size_t eapReqDataLen;
127         Boolean isEap;
128         int eap_type;
129         int user_selected_sim;
130         int eap_auth_session_flag[MAX_NO_OF_SIM_SUPPORTED];
131         int notification_code;
132         pthread_t thread_id;
133         wpa_uim_struct_type   wpa_uim[MAX_NO_OF_SIM_SUPPORTED];
134         Boolean qmi_uim_svc_client_initialized[MAX_NO_OF_SIM_SUPPORTED];
135 };
136 
137 int eap_proxy_allowed_method(struct eap_peer_config *config, int vendor,
138                               u32 method);
139 
140 #endif /* EAP_PROXY_QMI_H */
141