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 met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 * Neither the name of The Linux Foundation nor
12 the names of its contributors may be used to endorse or promote
13 products derived from this software without specific prior written
14 permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 --------------------------------------------------------------------------*/
28
29 #ifdef WCNSS_QMI
30 #define LOG_TAG "wcnss_qmi"
31 #include <cutils/log.h>
32 #include "wcnss_qmi_client.h"
33 #include "qmi_client.h"
34 #include "device_management_service_v01.h"
35 #include <cutils/properties.h>
36 #include <string.h>
37
38 #define SUCCESS 0
39 #define FAILED -1
40
41 #define WLAN_ADDR_SIZE 6
42 #define DMS_QMI_TIMEOUT (2000)
43
44 static qmi_client_type dms_qmi_client;
45 static int dms_init_done = FAILED;
46
wcnss_init_qmi()47 int wcnss_init_qmi()
48 {
49 qmi_client_error_type qmi_client_err;
50
51 ALOGE("%s: Initialize wcnss QMI Interface", __func__);
52 qmi_client_os_params dms_os_params;
53
54 memset(&dms_os_params, 0, sizeof(qmi_client_os_params));
55 qmi_client_err = qmi_client_init_instance(dms_get_service_object_v01(),
56 QMI_CLIENT_INSTANCE_ANY, NULL, NULL,
57 &dms_os_params, 5000, &dms_qmi_client);
58
59 if (qmi_client_err != QMI_NO_ERR){
60 ALOGE("%s: Error while Initializing QMI Client: %d",
61 __func__, qmi_client_err);
62 goto exit;
63 }
64
65 dms_init_done = SUCCESS;
66 return SUCCESS;
67
68 exit:
69 return FAILED;
70 }
71
wcnss_qmi_get_wlan_address(unsigned char * pBdAddr)72 int wcnss_qmi_get_wlan_address(unsigned char *pBdAddr)
73 {
74 qmi_client_error_type qmi_client_err;
75 dms_get_mac_address_req_msg_v01 addr_req;
76 dms_get_mac_address_resp_msg_v01 addr_resp;
77
78 if ((dms_init_done == FAILED) || (pBdAddr == NULL)) {
79 ALOGE("%s: DMS init fail or pBdAddr is NULL", __func__);
80 return FAILED;
81 }
82
83 /* clear the request content */
84 memset(&addr_req, 0, sizeof(addr_req));
85
86 /*Request to get the WLAN MAC address */
87 addr_req.device = DMS_DEVICE_MAC_WLAN_V01;
88
89 qmi_client_err = qmi_client_send_msg_sync(dms_qmi_client,
90 QMI_DMS_GET_MAC_ADDRESS_REQ_V01, &addr_req, sizeof(addr_req),
91 &addr_resp, sizeof(addr_resp), DMS_QMI_TIMEOUT);
92
93 if (qmi_client_err != QMI_NO_ERR){
94 ALOGE("%s: Failed to get Rsp from Modem Error:%d",
95 __func__, qmi_client_err);
96 return FAILED;
97 }
98
99 ALOGE("%s: Mac Address_valid: %d Mac Address Len: %d",
100 __func__, addr_resp.mac_address_valid,
101 addr_resp.mac_address_len);
102
103 if (addr_resp.mac_address_valid &&
104 (addr_resp.mac_address_len == WLAN_ADDR_SIZE)) {
105 memcpy(pBdAddr, addr_resp.mac_address,
106 addr_resp.mac_address_len);
107 ALOGE("%s: Succesfully Read WLAN MAC Address", __func__);
108 return SUCCESS;
109 } else {
110 ALOGE("%s: Failed to Read WLAN MAC Address", __func__);
111 return FAILED;
112 }
113 }
114
wcnss_qmi_deinit()115 void wcnss_qmi_deinit()
116 {
117 qmi_client_error_type qmi_client_err;
118
119 ALOGE("%s: Deinitialize wcnss QMI Interface", __func__);
120
121 if (dms_init_done == FAILED) {
122 ALOGE("%s: DMS Service was not Initialized", __func__);
123 return;
124 }
125
126 qmi_client_err = qmi_client_release(dms_qmi_client);
127
128 if (qmi_client_err != QMI_NO_ERR){
129 ALOGE("%s: Error while releasing qmi_client: %d",
130 __func__, qmi_client_err);
131 }
132
133 dms_init_done = FAILED;
134 }
135 #endif
136