• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "sync.h"
18 #include <utils/Log.h>
19 #include "wifi_hal.h"
20 #include "nan_i.h"
21 #include "nancommand.h"
22 
23 
isNanResponse()24 int NanCommand::isNanResponse()
25 {
26     if (mNanVendorEvent == NULL) {
27         ALOGE("NULL check failed");
28         return WIFI_ERROR_INVALID_ARGS;
29     }
30 
31     NanMsgHeader *pHeader = (NanMsgHeader *)mNanVendorEvent;
32 
33     switch (pHeader->msgId) {
34     case NAN_MSG_ID_ERROR_RSP:
35     case NAN_MSG_ID_CONFIGURATION_RSP:
36     case NAN_MSG_ID_PUBLISH_SERVICE_CANCEL_RSP:
37     case NAN_MSG_ID_PUBLISH_SERVICE_RSP:
38     case NAN_MSG_ID_SUBSCRIBE_SERVICE_RSP:
39     case NAN_MSG_ID_SUBSCRIBE_SERVICE_CANCEL_RSP:
40     case NAN_MSG_ID_TRANSMIT_FOLLOWUP_RSP:
41     case NAN_MSG_ID_STATS_RSP:
42     case NAN_MSG_ID_ENABLE_RSP:
43     case NAN_MSG_ID_DISABLE_RSP:
44     case NAN_MSG_ID_TCA_RSP:
45     case NAN_MSG_ID_BEACON_SDF_RSP:
46     case NAN_MSG_ID_CAPABILITIES_RSP:
47     case NAN_MSG_ID_TESTMODE_RSP:
48         return 1;
49     default:
50         return 0;
51     }
52 }
53 
54 struct verboseTlv {
55     NanTlvType tlvType;
56     char strTlv[NAN_ERROR_STR_LEN];
57 };
58 
59 struct verboseTlv tlvToStr[] = {
60     {NAN_TLV_TYPE_SDF_MATCH_FILTER, " SDF match filter"},
61     {NAN_TLV_TYPE_TX_MATCH_FILTER, " Tx match filter"},
62     {NAN_TLV_TYPE_RX_MATCH_FILTER, " Rx match filter"},
63     {NAN_TLV_TYPE_SERVICE_SPECIFIC_INFO,
64      " Service specific info"},
65     {NAN_TLV_TYPE_EXT_SERVICE_SPECIFIC_INFO,
66      " Extended Service specific info"},
67     {NAN_TLV_TYPE_VENDOR_SPECIFIC_ATTRIBUTE_TRANSMIT,
68      " Vendor specific attribute transmit"},
69     {NAN_TLV_TYPE_VENDOR_SPECIFIC_ATTRIBUTE_RECEIVE,
70      " Vendor specific attribute receive"},
71     {NAN_TLV_TYPE_POST_NAN_CONNECTIVITY_CAPABILITIES_RECEIVE,
72      " Post Nan connectivity capability receive"},
73     {NAN_TLV_TYPE_POST_NAN_DISCOVERY_ATTRIBUTE_RECEIVE,
74      " Post Nan discovery attribute receive"},
75     {NAN_TLV_TYPE_BEACON_SDF_PAYLOAD_RECEIVE,
76      " Beacon SDF payload receive"},
77 
78     /* Configuration types */
79     {NAN_TLV_TYPE_CONFIG_FIRST, " Config first"},
80     {NAN_TLV_TYPE_24G_SUPPORT, " 2.4G support"},
81     {NAN_TLV_TYPE_24G_BEACON, " 2.4G beacon"},
82     {NAN_TLV_TYPE_24G_SDF, " 2.4G SDF"},
83     {NAN_TLV_TYPE_24G_RSSI_CLOSE, " 2.4G RSSI close"},
84     {NAN_TLV_TYPE_24G_RSSI_MIDDLE, " 2.4G RSSI middle"},
85     {NAN_TLV_TYPE_24G_RSSI_CLOSE_PROXIMITY,
86      " 2.4G RSSI close proximity"},
87     {NAN_TLV_TYPE_5G_SUPPORT, " 5G support"},
88     {NAN_TLV_TYPE_5G_BEACON, " 5G beacon"},
89     {NAN_TLV_TYPE_5G_SDF, " 5G SDF"},
90     {NAN_TLV_TYPE_5G_RSSI_CLOSE, " 5G RSSI close"},
91     {NAN_TLV_TYPE_5G_RSSI_MIDDLE, " 5G RSSI middle"},
92     {NAN_TLV_TYPE_5G_RSSI_CLOSE_PROXIMITY,
93      " 5G RSSI close proximity"},
94     {NAN_TLV_TYPE_SID_BEACON, " SID beacon"},
95     {NAN_TLV_TYPE_HOP_COUNT_LIMIT, " Hop count limit"},
96     {NAN_TLV_TYPE_MASTER_PREFERENCE, " Master preference"},
97     {NAN_TLV_TYPE_CLUSTER_ID_LOW, " Cluster ID low"},
98     {NAN_TLV_TYPE_CLUSTER_ID_HIGH, " Cluster ID high"},
99     {NAN_TLV_TYPE_RSSI_AVERAGING_WINDOW_SIZE,
100      " RSSI averaging window size"},
101     {NAN_TLV_TYPE_CLUSTER_OUI_NETWORK_ID,
102      " Cluster OUI network ID"},
103     {NAN_TLV_TYPE_SOURCE_MAC_ADDRESS,
104      " Source MAC address"},
105     {NAN_TLV_TYPE_CLUSTER_ATTRIBUTE_IN_SDF,
106      " Cluster attribute in SDF"},
107     {NAN_TLV_TYPE_SOCIAL_CHANNEL_SCAN_PARAMS,
108      " Social channel scan params"},
109     {NAN_TLV_TYPE_DEBUGGING_FLAGS, " Debugging flags"},
110     {NAN_TLV_TYPE_POST_NAN_CONNECTIVITY_CAPABILITIES_TRANSMIT,
111      " Post nan connectivity capabilities transmit"},
112     {NAN_TLV_TYPE_POST_NAN_DISCOVERY_ATTRIBUTE_TRANSMIT,
113      " Post nan discovery attribute transmit"},
114     {NAN_TLV_TYPE_FURTHER_AVAILABILITY_MAP,
115      " Further availability map"},
116     {NAN_TLV_TYPE_HOP_COUNT_FORCE, " Hop count force"},
117     {NAN_TLV_TYPE_RANDOM_FACTOR_FORCE,
118      " Random factor force"},
119     {NAN_TLV_TYPE_RANDOM_UPDATE_TIME,
120      " Random update time"},
121     {NAN_TLV_TYPE_EARLY_WAKEUP, " Early wakeup"},
122     {NAN_TLV_TYPE_PERIODIC_SCAN_INTERVAL,
123      " Periodic scan interval"},
124     {NAN_TLV_TYPE_DW_INTERVAL, " DW interval"},
125     {NAN_TLV_TYPE_DB_INTERVAL, " DB interval"},
126     {NAN_TLV_TYPE_FURTHER_AVAILABILITY,
127      " Further availability"},
128     {NAN_TLV_TYPE_24G_CHANNEL, " 2.4G channel"},
129     {NAN_TLV_TYPE_5G_CHANNEL, " 5G channel"},
130     {NAN_TLV_TYPE_CONFIG_LAST, " Config last"},
131 
132     /* Attributes types */
133     {NAN_TLV_TYPE_ATTRS_FIRST, " Attributes first"},
134     {NAN_TLV_TYPE_AVAILABILITY_INTERVALS_MAP,
135      " Availability intervals map"},
136     {NAN_TLV_TYPE_WLAN_MESH_ID, " WLAN mesh ID"},
137     {NAN_TLV_TYPE_MAC_ADDRESS, " MAC address"},
138     {NAN_TLV_TYPE_RECEIVED_RSSI_VALUE,
139      " Received RSSI value"},
140     {NAN_TLV_TYPE_CLUSTER_ATTRIBUTE,
141      " Cluster attribute"},
142     {NAN_TLV_TYPE_WLAN_INFRA_SSID, " WLAN infra SSID"},
143     {NAN_TLV_TYPE_ATTRS_LAST, " Attributes last"},
144 
145     /* Events Type */
146     {NAN_TLV_TYPE_EVENTS_FIRST, " Events first"},
147     {NAN_TLV_TYPE_EVENT_SELF_STATION_MAC_ADDRESS,
148      " Event Self station MAC address"},
149     {NAN_TLV_TYPE_EVENT_STARTED_CLUSTER,
150      " Event started cluster"},
151     {NAN_TLV_TYPE_EVENT_JOINED_CLUSTER,
152      " Event joined cluster"},
153     {NAN_TLV_TYPE_EVENT_CLUSTER_SCAN_RESULTS,
154      " Event cluster scan results"},
155     {NAN_TLV_TYPE_FAW_MEM_AVAIL,
156      " FAW memory availability"},
157     {NAN_TLV_TYPE_EVENTS_LAST, " Events last"},
158 
159     /* TCA types */
160     {NAN_TLV_TYPE_TCA_FIRST, " TCA-Threshold Crossing Alert first"},
161     {NAN_TLV_TYPE_CLUSTER_SIZE_REQ,
162      " Cluster size request"},
163     {NAN_TLV_TYPE_CLUSTER_SIZE_RSP,
164      " Cluster size response"},
165     {NAN_TLV_TYPE_TCA_LAST, " TCA last"},
166 
167     /* Statistics types */
168     {NAN_TLV_TYPE_STATS_FIRST, " Stats first"},
169     {NAN_TLV_TYPE_DE_PUBLISH_STATS,
170      " Discovery engine publish stats"},
171     {NAN_TLV_TYPE_DE_SUBSCRIBE_STATS,
172      " Discovery engine subscribe stats"},
173     {NAN_TLV_TYPE_DE_MAC_STATS,
174      " Discovery engine MAC stats"},
175     {NAN_TLV_TYPE_DE_TIMING_SYNC_STATS,
176      " Discovery engine timing sync stats"},
177     {NAN_TLV_TYPE_DE_DW_STATS,
178      " Discovery engine DW stats"},
179     {NAN_TLV_TYPE_DE_STATS, " Discovery engine stats"},
180     {NAN_TLV_TYPE_STATS_LAST, " Stats last"},
181 
182     {NAN_TLV_TYPE_LAST, " Last"}
183 };
184 
185 struct errorCode {
186     NanStatusType frameworkError;
187     NanInternalStatusType firmwareError;
188     char nan_error[NAN_ERROR_STR_LEN];
189 };
190 
191 struct errorCode errorCodeTranslation[] = {
192     {NAN_STATUS_SUCCESS, NAN_I_STATUS_SUCCESS,
193      "NAN status success"},
194 
195     {NAN_STATUS_INTERNAL_FAILURE, NAN_I_STATUS_DE_FAILURE,
196      "NAN Discovery engine failure"},
197 
198     {NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID, NAN_I_STATUS_INVALID_HANDLE,
199      "Invalid Publish/Subscribe ID"},
200 
201     {NAN_STATUS_NO_RESOURCE_AVAILABLE, NAN_I_STATUS_NO_SPACE_AVAILABLE,
202      "No space available"},
203 
204     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_PUBLISH_TYPE,
205      "Invalid Publish type, can be 0 or 1"},
206     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_TX_TYPE,
207      "Invalid Tx type"},
208     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_MSG_VERSION,
209      "Invalid internal message version"},
210     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_MSG_LEN,
211      "Invalid message length"},
212     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_MSG_ID,
213      "Invalid message ID"},
214     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_MATCH_ALGORITHM,
215      "Invalid matching algorithm, can be 0(match once), 1(match continuous) or 2(match never)"},
216     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_TLV_LEN,
217      "Invalid TLV length"},
218     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_TLV_TYPE,
219      "Invalid TLV type"},
220     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_MISSING_TLV_TYPE,
221      "Missing TLV type"},
222     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_TOTAL_TLVS_LEN,
223      "Invalid total TLV length"},
224     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_TLV_VALUE,
225      "Invalid TLV value"},
226     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_TX_PRIORITY,
227      "Invalid Tx priority"},
228     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_CONNECTION_MAP,
229      "Invalid connection map"},
230     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_THRESHOLD_CROSSING_ALERT_ID,
231      "Invalid TCA-Threshold Crossing Alert ID"},
232     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_STATS_ID,
233      "Invalid STATS ID"},
234 
235     {NAN_STATUS_PROTOCOL_FAILURE, NAN_I_STATUS_TX_FAIL,
236      "Tx Fail"},
237 
238     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_RSSI_CLOSE_VALUE,
239      "Invalid RSSI close value range is 20dbm to 60dbm"},
240     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_RSSI_MIDDLE_VALUE,
241      "Invalid RSSI middle value range is 20dbm to 75dbm"},
242     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_HOP_COUNT_LIMIT,
243      "Invalid hop count limit, max hop count limit is 5"},
244     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_HIGH_CLUSTER_ID_VALUE,
245      "Invalid cluster ID value. Please set the cluster id high greater than the cluster id low"},
246     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_BACKGROUND_SCAN_PERIOD,
247      "Invalid background scan period. The range is 10 to 30 milliseconds"},
248     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_SCAN_CHANNEL,
249      "Invalid scan channel. Only valid channels are the NAN social channels"},
250     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_POST_NAN_CONNECTIVITY_CAPABILITIES_BITMAP,
251      "Invalid post nan connectivity bitmap"},
252     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_NUMCHAN_VALUE,
253      "Invalid further availability map number of channel value"},
254     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_DURATION_VALUE,
255      "Invalid further availability map duration value"},
256     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_CLASS_VALUE,
257      "Invalid further availability map class value"},
258     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_CHANNEL_VALUE,
259      "Invalid further availability map channel value"},
260     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_AVAILABILITY_INTERVAL_BITMAP_VALUE,
261      "Invalid further availability map availability interval bitmap value"},
262     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_FURTHER_AVAILABILITY_MAP_MAP_ID,
263      "Invalid further availability map map ID"},
264     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_CONN_TYPE_VALUE,
265      "Invalid post nan discovery connection type value"},
266     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_DEVICE_ROLE_VALUE,
267      "Invalid post nan discovery device role value"},
268     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_DURATION_VALUE,
269      "Invalid post nan discovery duration value"},
270     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_POST_NAN_DISCOVERY_BITMAP_VALUE,
271      "Invalid post nan discovery bitmap value"},
272     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_MISSING_FUTHER_AVAILABILITY_MAP,
273      "Missing further availability map"},
274     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_BAND_CONFIG_FLAGS,
275      "Invalid band configuration flags"},
276     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_RANDOM_FACTOR_UPDATE_TIME_VALUE,
277      "Invalid random factor update time value"},
278     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_ONGOING_SCAN_PERIOD,
279      "Invalid ongoing scan period"},
280     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_DW_INTERVAL_VALUE,
281      "Invalid DW interval value"},
282     {NAN_STATUS_INVALID_PARAM, NAN_I_STATUS_INVALID_DB_INTERVAL_VALUE,
283      "Invalid DB interval value"},
284 
285     {NAN_STATUS_SUCCESS, NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_TIMEOUT,
286      "Terminated Reason: Timeout"},
287     {NAN_STATUS_SUCCESS, NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_USER_REQUEST,
288      "Terminated Reason: User Request"},
289     {NAN_STATUS_SUCCESS, NAN_I_PUBLISH_SUBSCRIBE_TERMINATED_REASON_COUNT_REACHED,
290      "Terminated Reason: Count Reached"},
291 
292     {NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID, NAN_I_STATUS_INVALID_REQUESTER_INSTANCE_ID,
293      "Invalid match handle"},
294     {NAN_STATUS_NAN_NOT_ALLOWED, NAN_I_STATUS_NAN_NOT_ALLOWED,
295      "Nan not allowed"},
296     {NAN_STATUS_NO_OTA_ACK, NAN_I_STATUS_NO_OTA_ACK,
297      "No OTA ack"},
298     {NAN_STATUS_ALREADY_ENABLED, NAN_I_STATUS_NAN_ALREADY_ENABLED,
299      "NAN is Already enabled"},
300     {NAN_STATUS_FOLLOWUP_QUEUE_FULL, NAN_I_STATUS_FOLLOWUP_QUEUE_FULL,
301      "Follow-up queue full"},
302 
303     {NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED, NDP_I_UNSUPPORTED_CONCURRENCY,
304      "Unsupported Concurrency"},
305 
306     {NAN_STATUS_INTERNAL_FAILURE, NDP_I_NAN_DATA_IFACE_CREATE_FAILED,
307      "NAN data interface create failed"},
308     {NAN_STATUS_INTERNAL_FAILURE, NDP_I_NAN_DATA_IFACE_DELETE_FAILED,
309      "NAN data interface delete failed"},
310     {NAN_STATUS_INTERNAL_FAILURE, NDP_I_DATA_INITIATOR_REQUEST_FAILED,
311      "NAN data initiator request failed"},
312     {NAN_STATUS_INTERNAL_FAILURE, NDP_I_DATA_RESPONDER_REQUEST_FAILED,
313      "NAN data responder request failed"},
314 
315     {NAN_STATUS_INVALID_NDP_ID, NDP_I_INVALID_NDP_INSTANCE_ID,
316      "Invalid NDP instance ID"},
317 
318     {NAN_STATUS_INVALID_PARAM, NDP_I_INVALID_RESPONSE_CODE,
319      "Invalid response code"},
320     {NAN_STATUS_INVALID_PARAM, NDP_I_INVALID_APP_INFO_LEN,
321      "Invalid app info length"},
322 
323     {NAN_STATUS_PROTOCOL_FAILURE, NDP_I_MGMT_FRAME_REQUEST_FAILED,
324      "Management frame request failed"},
325     {NAN_STATUS_PROTOCOL_FAILURE, NDP_I_MGMT_FRAME_RESPONSE_FAILED,
326      "Management frame response failed"},
327     {NAN_STATUS_PROTOCOL_FAILURE, NDP_I_MGMT_FRAME_CONFIRM_FAILED,
328      "Management frame confirm failed"},
329 
330     {NAN_STATUS_INTERNAL_FAILURE, NDP_I_END_FAILED,
331      "NDP end failed"},
332 
333     {NAN_STATUS_PROTOCOL_FAILURE, NDP_I_MGMT_FRAME_END_REQUEST_FAILED,
334      "Management frame end request failed"},
335 
336     {NAN_STATUS_INTERNAL_FAILURE, NDP_I_VENDOR_SPECIFIC_ERROR,
337      "Vendor specific error"}
338 };
339 
NanErrorTranslation(NanInternalStatusType firmwareErrorRecvd,u32 valueRcvd,void * pResponse,bool is_ndp_rsp)340 void NanCommand::NanErrorTranslation(NanInternalStatusType firmwareErrorRecvd,
341                                      u32 valueRcvd,
342                                      void* pResponse,
343                                      bool is_ndp_rsp)
344 {
345     int i = 0, j = 0;
346     u16 msg_id; /* Based on the message_id in the header determine the Indication type */
347     NanResponseMsg *pRsp;
348     NanPublishTerminatedInd* pRspInd;
349     NanDisabledInd* pRspdInd;
350     char tlvInfo[NAN_ERROR_STR_LEN];
351     tlvInfo[0] = '\0';
352 
353     if (isNanResponse() || (is_ndp_rsp == true)){
354         pRsp = (NanResponseMsg*)pResponse;
355         for (i = 0; i < (int)(sizeof(errorCodeTranslation)/ sizeof(errorCode)); i++) {
356             if (errorCodeTranslation[i].firmwareError == firmwareErrorRecvd) {
357                 pRsp->status =  errorCodeTranslation[i].frameworkError;
358                 strlcpy(pRsp->nan_error, errorCodeTranslation[i].nan_error, NAN_ERROR_STR_LEN);
359                 if (NAN_I_STATUS_INVALID_TLV_TYPE == firmwareErrorRecvd) {
360                     for (j = 0; j < (int)(sizeof(tlvToStr)/sizeof(verboseTlv)); j++) {
361                         if (tlvToStr[j].tlvType == valueRcvd) {
362                             strlcpy(tlvInfo, tlvToStr[i].strTlv, NAN_ERROR_STR_LEN);
363                             break;
364                         }
365                     }
366                 }
367                 strlcat(pRsp->nan_error, tlvInfo, sizeof(pRsp->nan_error));
368                 break;
369             }
370         }
371         if (i == (int)(sizeof(errorCodeTranslation)/sizeof(errorCode))) {
372                 pRsp->status =  NAN_STATUS_INTERNAL_FAILURE;
373                 strlcpy(pRsp->nan_error, "NAN Discovery engine failure", NAN_ERROR_STR_LEN);
374         }
375         ALOGD("%s: Status: %d Error Info[value %d]: %s", __FUNCTION__, pRsp->status, valueRcvd, pRsp->nan_error);
376     } else {
377         msg_id = getIndicationType();
378 
379         switch(msg_id) {
380         case NAN_INDICATION_PUBLISH_TERMINATED:
381         case NAN_INDICATION_SUBSCRIBE_TERMINATED:
382         case NAN_INDICATION_SELF_TRANSMIT_FOLLOWUP:
383                 pRspInd = (NanPublishTerminatedInd*)pResponse;
384                 for (i = 0; i < (int)(sizeof(errorCodeTranslation)/ sizeof(errorCode)); i++) {
385                         if (errorCodeTranslation[i].firmwareError == firmwareErrorRecvd) {
386                                 pRspInd->reason =  errorCodeTranslation[i].frameworkError;
387                                 strlcpy(pRspInd->nan_reason, errorCodeTranslation[i].nan_error, NAN_ERROR_STR_LEN);
388                                 break;
389                         }
390                 }
391                 if (i == (int)(sizeof(errorCodeTranslation)/sizeof(errorCode))) {
392                         pRspInd->reason =  NAN_STATUS_INTERNAL_FAILURE;
393                         strlcpy(pRspInd->nan_reason, "NAN Discovery engine failure", NAN_ERROR_STR_LEN);
394                 }
395                 ALOGD("%s: Status: %d Error Info[value %d]: %s", __FUNCTION__, pRspInd->reason, valueRcvd, pRspInd->nan_reason);
396                 break;
397         case NAN_INDICATION_DISABLED:
398                 pRspdInd = (NanDisabledInd*)pResponse;
399                 for (i = 0; i < (int)(sizeof(errorCodeTranslation)/ sizeof(errorCode)); i++) {
400                         if (errorCodeTranslation[i].firmwareError == firmwareErrorRecvd) {
401                                 pRspdInd->reason =  errorCodeTranslation[i].frameworkError;
402                                 strlcpy(pRspdInd->nan_reason, errorCodeTranslation[i].nan_error, NAN_ERROR_STR_LEN);
403                                 break;
404                         }
405                 }
406                 if (i == (int)(sizeof(errorCodeTranslation)/sizeof(errorCode))) {
407                         pRspdInd->reason =  NAN_STATUS_INTERNAL_FAILURE;
408                         strlcpy(pRspdInd->nan_reason, "NAN Discovery engine failure", NAN_ERROR_STR_LEN);
409                 }
410                 ALOGD("%s: Status: %d Error Info[value %d]: %s", __FUNCTION__, pRspdInd->reason, valueRcvd, pRspdInd->nan_reason);
411                 break;
412         }
413     }
414 }
415 
getNanResponse(transaction_id * id,NanResponseMsg * pRsp)416 int NanCommand::getNanResponse(transaction_id *id, NanResponseMsg *pRsp)
417 {
418     if (mNanVendorEvent == NULL || pRsp == NULL) {
419         ALOGE("NULL check failed");
420         return WIFI_ERROR_INVALID_ARGS;
421     }
422 
423     NanMsgHeader *pHeader = (NanMsgHeader *)mNanVendorEvent;
424 
425     switch (pHeader->msgId) {
426         case NAN_MSG_ID_ERROR_RSP:
427         {
428             pNanErrorRspMsg pFwRsp = \
429                 (pNanErrorRspMsg)mNanVendorEvent;
430             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
431             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
432             pRsp->response_type = NAN_RESPONSE_ERROR;
433             break;
434         }
435         case NAN_MSG_ID_CONFIGURATION_RSP:
436         {
437             pNanConfigurationRspMsg pFwRsp = \
438                 (pNanConfigurationRspMsg)mNanVendorEvent;
439             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
440             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
441             pRsp->response_type = NAN_RESPONSE_CONFIG;
442         }
443         break;
444         case NAN_MSG_ID_PUBLISH_SERVICE_CANCEL_RSP:
445         {
446             pNanPublishServiceCancelRspMsg pFwRsp = \
447                 (pNanPublishServiceCancelRspMsg)mNanVendorEvent;
448             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
449             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
450             pRsp->response_type = NAN_RESPONSE_PUBLISH_CANCEL;
451             pRsp->body.publish_response.publish_id = \
452                 pFwRsp->fwHeader.handle;
453             break;
454         }
455         case NAN_MSG_ID_PUBLISH_SERVICE_RSP:
456         {
457             pNanPublishServiceRspMsg pFwRsp = \
458                 (pNanPublishServiceRspMsg)mNanVendorEvent;
459             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
460             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
461             pRsp->response_type = NAN_RESPONSE_PUBLISH;
462             pRsp->body.publish_response.publish_id = \
463                 pFwRsp->fwHeader.handle;
464             break;
465         }
466         case NAN_MSG_ID_SUBSCRIBE_SERVICE_RSP:
467         {
468             pNanSubscribeServiceRspMsg pFwRsp = \
469                 (pNanSubscribeServiceRspMsg)mNanVendorEvent;
470             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
471             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
472             pRsp->response_type = NAN_RESPONSE_SUBSCRIBE;
473             pRsp->body.subscribe_response.subscribe_id = \
474                 pFwRsp->fwHeader.handle;
475         }
476         break;
477         case NAN_MSG_ID_SUBSCRIBE_SERVICE_CANCEL_RSP:
478         {
479             pNanSubscribeServiceCancelRspMsg pFwRsp = \
480                 (pNanSubscribeServiceCancelRspMsg)mNanVendorEvent;
481             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
482             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
483             pRsp->response_type = NAN_RESPONSE_SUBSCRIBE_CANCEL;
484             pRsp->body.subscribe_response.subscribe_id = \
485                 pFwRsp->fwHeader.handle;
486             break;
487         }
488         case NAN_MSG_ID_TRANSMIT_FOLLOWUP_RSP:
489         {
490             pNanTransmitFollowupRspMsg pFwRsp = \
491                 (pNanTransmitFollowupRspMsg)mNanVendorEvent;
492             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
493             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
494             pRsp->response_type = NAN_RESPONSE_TRANSMIT_FOLLOWUP;
495             break;
496         }
497         case NAN_MSG_ID_STATS_RSP:
498         {
499             pNanStatsRspMsg pFwRsp = \
500                 (pNanStatsRspMsg)mNanVendorEvent;
501             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
502             NanErrorTranslation((NanInternalStatusType)pFwRsp->statsRspParams.status,
503                                             pFwRsp->statsRspParams.value, pRsp, false);
504             pRsp->response_type = NAN_RESPONSE_STATS;
505             pRsp->body.stats_response.stats_type = \
506                 (NanStatsType)pFwRsp->statsRspParams.statsType;
507             ALOGV("%s: stats_type:%d",__func__,
508                   pRsp->body.stats_response.stats_type);
509             u8 *pInputTlv = pFwRsp->ptlv;
510             NanTlv outputTlv;
511             memset(&outputTlv, 0, sizeof(outputTlv));
512             u16 readLen = 0;
513             int remainingLen = (mNanDataLen -  \
514                 (sizeof(NanMsgHeader) + sizeof(NanStatsRspParams)));
515             if (remainingLen > 0) {
516                 readLen = NANTLV_ReadTlv(pInputTlv, &outputTlv);
517                 ALOGV("%s: Remaining Len:%d readLen:%d type:%d length:%d",
518                       __func__, remainingLen, readLen, outputTlv.type,
519                       outputTlv.length);
520                 if (outputTlv.length <= \
521                     sizeof(pRsp->body.stats_response.data)) {
522                     handleNanStatsResponse(pRsp->body.stats_response.stats_type,
523                                            (char *)outputTlv.value,
524                                            &pRsp->body.stats_response,
525                                            outputTlv.length);
526                 }
527             } else
528                 ALOGV("%s: No TLV's present",__func__);
529             break;
530         }
531         case NAN_MSG_ID_ENABLE_RSP:
532         {
533             pNanEnableRspMsg pFwRsp = \
534                 (pNanEnableRspMsg)mNanVendorEvent;
535             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
536             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
537             pRsp->response_type = NAN_RESPONSE_ENABLED;
538             break;
539         }
540         case NAN_MSG_ID_DISABLE_RSP:
541         {
542             pNanDisableRspMsg pFwRsp = \
543                 (pNanDisableRspMsg)mNanVendorEvent;
544             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
545             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, 0, pRsp, false);
546             pRsp->response_type = NAN_RESPONSE_DISABLED;
547             break;
548         }
549         case NAN_MSG_ID_TCA_RSP:
550         {
551             pNanTcaRspMsg pFwRsp = \
552                 (pNanTcaRspMsg)mNanVendorEvent;
553             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
554             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
555             pRsp->response_type = NAN_RESPONSE_TCA;
556             break;
557         }
558         case NAN_MSG_ID_BEACON_SDF_RSP:
559         {
560             pNanBeaconSdfPayloadRspMsg pFwRsp = \
561                 (pNanBeaconSdfPayloadRspMsg)mNanVendorEvent;
562             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
563             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, 0, pRsp, false);
564             pRsp->response_type = NAN_RESPONSE_BEACON_SDF_PAYLOAD;
565             break;
566         }
567         case NAN_MSG_ID_CAPABILITIES_RSP:
568         {
569             pNanCapabilitiesRspMsg pFwRsp = \
570                 (pNanCapabilitiesRspMsg)mNanVendorEvent;
571             *id = (transaction_id)pFwRsp->fwHeader.transactionId;
572             NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp, false);
573             pRsp->response_type = NAN_GET_CAPABILITIES;
574             pRsp->body.nan_capabilities.max_concurrent_nan_clusters = \
575                         pFwRsp->max_concurrent_nan_clusters;
576             pRsp->body.nan_capabilities.max_publishes = \
577                         pFwRsp->max_publishes;
578             pRsp->body.nan_capabilities.max_subscribes = \
579                         pFwRsp->max_subscribes;
580             pRsp->body.nan_capabilities.max_service_name_len = \
581                         pFwRsp->max_service_name_len;
582             pRsp->body.nan_capabilities.max_match_filter_len = \
583                         pFwRsp->max_match_filter_len;
584             pRsp->body.nan_capabilities.max_total_match_filter_len = \
585                         pFwRsp->max_total_match_filter_len;
586             pRsp->body.nan_capabilities.max_service_specific_info_len = \
587                         pFwRsp->max_service_specific_info_len;
588             pRsp->body.nan_capabilities.max_vsa_data_len = \
589                         pFwRsp->max_vsa_data_len;
590             pRsp->body.nan_capabilities.max_mesh_data_len = \
591                         pFwRsp->max_mesh_data_len;
592             pRsp->body.nan_capabilities.max_ndi_interfaces = \
593                        pFwRsp->max_ndi_interfaces;
594             pRsp->body.nan_capabilities.max_ndp_sessions = \
595                        pFwRsp->max_ndp_sessions;
596             pRsp->body.nan_capabilities.max_app_info_len = \
597                        pFwRsp->max_app_info_len;
598             pRsp->body.nan_capabilities.max_queued_transmit_followup_msgs = \
599                        pFwRsp->max_queued_transmit_followup_msgs;
600             pRsp->body.nan_capabilities.ndp_supported_bands = \
601                        pFwRsp->ndp_supported_bands;
602             pRsp->body.nan_capabilities.cipher_suites_supported = \
603                        pFwRsp->cipher_suites_supported;
604             pRsp->body.nan_capabilities.max_scid_len = \
605                        pFwRsp->max_scid_len;
606             pRsp->body.nan_capabilities.is_ndp_security_supported = \
607                        pFwRsp->is_ndp_security_supported;
608             pRsp->body.nan_capabilities.max_sdea_service_specific_info_len = \
609                        pFwRsp->max_sdea_service_specific_info_len;
610             pRsp->body.nan_capabilities.max_subscribe_address = \
611                        pFwRsp->max_subscribe_address;
612             pRsp->body.nan_capabilities.ndpe_attr_supported = \
613                        pFwRsp->ndpe_attr_supported;
614             break;
615         }
616         default:
617             return  -1;
618     }
619     return  0;
620 }
621 
handleNanResponse()622 int NanCommand::handleNanResponse()
623 {
624     //parse the data and call
625     //the response callback handler with the populated
626     //NanResponseMsg
627     NanResponseMsg  rsp_data;
628     int ret;
629     transaction_id id;
630 
631     ALOGV("handleNanResponse called %p", this);
632     memset(&rsp_data, 0, sizeof(rsp_data));
633     //get the rsp_data
634     ret = getNanResponse(&id, &rsp_data);
635 
636     ALOGI("handleNanResponse ret:%d status:%u value:%s response_type:%u",
637           ret, rsp_data.status, rsp_data.nan_error, rsp_data.response_type);
638     if (ret == 0 && (rsp_data.response_type == NAN_RESPONSE_STATS) &&
639         (mStaParam != NULL) &&
640         (rsp_data.body.stats_response.stats_type == NAN_STATS_ID_DE_TIMING_SYNC)) {
641         /*
642            Fill the staParam with appropriate values and return from here.
643            No need to call NotifyResponse as the request is for getting the
644            STA response
645         */
646         NanSyncStats *pSyncStats = &rsp_data.body.stats_response.data.sync_stats;
647         mStaParam->master_rank = pSyncStats->myRank;
648         mStaParam->master_pref = (pSyncStats->myRank & 0xFF00000000000000) >> 56;
649         mStaParam->random_factor = (pSyncStats->myRank & 0x00FF000000000000) >> 48;
650         mStaParam->hop_count = pSyncStats->currAmHopCount;
651         mStaParam->beacon_transmit_time = pSyncStats->currAmBTT;
652         mStaParam->ndp_channel_freq = pSyncStats->ndpChannelFreq;
653 
654         ALOGI("%s:0x%02x master_pref 0x%02x random_factor 0x%02x hop_count %u Channel",
655                 __func__, mStaParam->master_pref, mStaParam->random_factor,
656                 mStaParam->hop_count, mStaParam->ndp_channel_freq);
657 
658         return ret;
659     }
660     //Call the NotifyResponse Handler
661     if (ret == 0 && mHandler.NotifyResponse) {
662         (*mHandler.NotifyResponse)(id, &rsp_data);
663     }
664     return ret;
665 }
666 
handleNanStatsResponse(NanStatsType stats_type,char * rspBuf,NanStatsResponse * pRsp,u32 message_len)667 void NanCommand::handleNanStatsResponse(NanStatsType stats_type,
668                                        char *rspBuf,
669                                        NanStatsResponse *pRsp,
670                                        u32 message_len)
671 {
672     if (stats_type == NAN_STATS_ID_DE_PUBLISH) {
673         NanPublishStats publish_stats;
674         if (message_len != sizeof(NanPublishStats)) {
675             ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n",
676                     __func__, stats_type, message_len, sizeof(NanPublishStats));
677             return;
678         }
679         FwNanPublishStats *pPubStats = (FwNanPublishStats *)rspBuf;
680 
681         publish_stats.validPublishServiceReqMsgs =
682                                     pPubStats->validPublishServiceReqMsgs;
683         publish_stats.validPublishServiceRspMsgs =
684                                     pPubStats->validPublishServiceRspMsgs;
685         publish_stats.validPublishServiceCancelReqMsgs =
686                                     pPubStats->validPublishServiceCancelReqMsgs;
687         publish_stats.validPublishServiceCancelRspMsgs =
688                                     pPubStats->validPublishServiceCancelRspMsgs;
689         publish_stats.validPublishRepliedIndMsgs =
690                                     pPubStats->validPublishRepliedIndMsgs;
691         publish_stats.validPublishTerminatedIndMsgs =
692                                     pPubStats->validPublishTerminatedIndMsgs;
693         publish_stats.validActiveSubscribes = pPubStats->validActiveSubscribes;
694         publish_stats.validMatches = pPubStats->validMatches;
695         publish_stats.validFollowups = pPubStats->validFollowups;
696         publish_stats.invalidPublishServiceReqMsgs =
697                                     pPubStats->invalidPublishServiceReqMsgs;
698         publish_stats.invalidPublishServiceCancelReqMsgs =
699                                 pPubStats->invalidPublishServiceCancelReqMsgs;
700         publish_stats.invalidActiveSubscribes =
701                                 pPubStats->invalidActiveSubscribes;
702         publish_stats.invalidMatches = pPubStats->invalidMatches;
703         publish_stats.invalidFollowups = pPubStats->invalidFollowups;
704         publish_stats.publishCount = pPubStats->publishCount;
705         publish_stats.publishNewMatchCount = pPubStats->publishNewMatchCount;
706         publish_stats.pubsubGlobalNewMatchCount =
707                                pPubStats->pubsubGlobalNewMatchCount;
708         memcpy(&pRsp->data.publish_stats, &publish_stats, sizeof(NanPublishStats));
709     } else if (stats_type == NAN_STATS_ID_DE_SUBSCRIBE) {
710         NanSubscribeStats sub_stats;
711         if (message_len != sizeof(NanSubscribeStats)) {
712             ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n",
713                    __func__, stats_type, message_len, sizeof(NanSubscribeStats));
714             return;
715         }
716         FwNanSubscribeStats *pSubStats = (FwNanSubscribeStats *)rspBuf;
717 
718         sub_stats.validSubscribeServiceReqMsgs =
719                                 pSubStats->validSubscribeServiceReqMsgs;
720         sub_stats.validSubscribeServiceRspMsgs =
721                                 pSubStats->validSubscribeServiceRspMsgs;
722         sub_stats.validSubscribeServiceCancelReqMsgs =
723                                 pSubStats->validSubscribeServiceCancelReqMsgs;
724         sub_stats.validSubscribeServiceCancelRspMsgs =
725                                 pSubStats->validSubscribeServiceCancelRspMsgs;
726         sub_stats.validSubscribeTerminatedIndMsgs =
727                                 pSubStats->validSubscribeTerminatedIndMsgs;
728         sub_stats.validSubscribeMatchIndMsgs =
729                                 pSubStats->validSubscribeMatchIndMsgs;
730         sub_stats.validSubscribeUnmatchIndMsgs =
731                                 pSubStats->validSubscribeUnmatchIndMsgs;
732         sub_stats.validSolicitedPublishes =
733                                 pSubStats->validSolicitedPublishes;
734         sub_stats.validMatches = pSubStats->validMatches;
735         sub_stats.validFollowups = pSubStats->validFollowups;
736         sub_stats.invalidSubscribeServiceReqMsgs =
737                             pSubStats->invalidSubscribeServiceReqMsgs;
738         sub_stats.invalidSubscribeServiceCancelReqMsgs =
739                             pSubStats->invalidSubscribeServiceCancelReqMsgs;
740         sub_stats.invalidSubscribeFollowupReqMsgs =
741                             pSubStats->invalidSubscribeFollowupReqMsgs;
742         sub_stats.invalidSolicitedPublishes =
743                             pSubStats->invalidSolicitedPublishes;
744         sub_stats.invalidMatches = pSubStats->invalidMatches;
745         sub_stats.invalidFollowups = pSubStats->invalidFollowups;
746         sub_stats.subscribeCount = pSubStats->subscribeCount;
747         sub_stats.bloomFilterIndex = pSubStats->bloomFilterIndex;
748         sub_stats.subscribeNewMatchCount = pSubStats->subscribeNewMatchCount;
749         sub_stats.pubsubGlobalNewMatchCount =
750                                       pSubStats->pubsubGlobalNewMatchCount;
751         memcpy(&pRsp->data.subscribe_stats, &sub_stats, sizeof(NanSubscribeStats));
752     } else if (stats_type == NAN_STATS_ID_DE_DW) {
753         NanDWStats dw_stats;
754         if (message_len != sizeof(NanDWStats)) {
755             ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n",
756                    __func__, stats_type, message_len, sizeof(NanDWStats));
757             return;
758         }
759         FwNanMacStats *pMacStats = (FwNanMacStats *)rspBuf;
760 
761         dw_stats.validFrames = pMacStats->validFrames;
762         dw_stats.validActionFrames = pMacStats->validActionFrames;
763         dw_stats.validBeaconFrames = pMacStats->validBeaconFrames;
764         dw_stats.ignoredActionFrames = pMacStats->ignoredActionFrames;
765         dw_stats.ignoredBeaconFrames = pMacStats->ignoredBeaconFrames;
766         dw_stats.invalidFrames = pMacStats->invalidFrames;
767         dw_stats.invalidActionFrames = pMacStats->invalidActionFrames;
768         dw_stats.invalidBeaconFrames = pMacStats->invalidBeaconFrames;
769         dw_stats.invalidMacHeaders = pMacStats->invalidMacHeaders;
770         dw_stats.invalidPafHeaders  = pMacStats->invalidPafHeaders;
771         dw_stats.nonNanBeaconFrames = pMacStats->nonNanBeaconFrames;
772         dw_stats.earlyActionFrames = pMacStats->earlyActionFrames;
773         dw_stats.inDwActionFrames = pMacStats->inDwActionFrames;
774         dw_stats.lateActionFrames = pMacStats->lateActionFrames;
775         dw_stats.framesQueued =  pMacStats->framesQueued;
776         dw_stats.totalTRSpUpdates = pMacStats->totalTRSpUpdates;
777         dw_stats.completeByTRSp = pMacStats->completeByTRSp;
778         dw_stats.completeByTp75DW = pMacStats->completeByTp75DW;
779         dw_stats.completeByTendDW = pMacStats->completeByTendDW;
780         dw_stats.lateActionFramesTx = pMacStats->lateActionFramesTx;
781         memcpy(&pRsp->data.dw_stats, &dw_stats, sizeof(NanDWStats));
782     } else if (stats_type == NAN_STATS_ID_DE_MAC) {
783         NanMacStats mac_stats;
784         if (message_len != sizeof(NanMacStats)) {
785             ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n",
786                    __func__, stats_type, message_len, sizeof(NanMacStats));
787             return;
788         }
789         FwNanMacStats *pMacStats = (FwNanMacStats *)rspBuf;
790 
791         mac_stats.validFrames = pMacStats->validFrames;
792         mac_stats.validActionFrames = pMacStats->validActionFrames;
793         mac_stats.validBeaconFrames = pMacStats->validBeaconFrames;
794         mac_stats.ignoredActionFrames = pMacStats->ignoredActionFrames;
795         mac_stats.ignoredBeaconFrames = pMacStats->ignoredBeaconFrames;
796         mac_stats.invalidFrames = pMacStats->invalidFrames;
797         mac_stats.invalidActionFrames = pMacStats->invalidActionFrames;
798         mac_stats.invalidBeaconFrames = pMacStats->invalidBeaconFrames;
799         mac_stats.invalidMacHeaders = pMacStats->invalidMacHeaders;
800         mac_stats.invalidPafHeaders  = pMacStats->invalidPafHeaders;
801         mac_stats.nonNanBeaconFrames = pMacStats->nonNanBeaconFrames;
802         mac_stats.earlyActionFrames = pMacStats->earlyActionFrames;
803         mac_stats.inDwActionFrames = pMacStats->inDwActionFrames;
804         mac_stats.lateActionFrames = pMacStats->lateActionFrames;
805         mac_stats.framesQueued =  pMacStats->framesQueued;
806         mac_stats.totalTRSpUpdates = pMacStats->totalTRSpUpdates;
807         mac_stats.completeByTRSp = pMacStats->completeByTRSp;
808         mac_stats.completeByTp75DW = pMacStats->completeByTp75DW;
809         mac_stats.completeByTendDW = pMacStats->completeByTendDW;
810         mac_stats.lateActionFramesTx = pMacStats->lateActionFramesTx;
811         mac_stats.twIncreases = pMacStats->twIncreases;
812         mac_stats.twDecreases = pMacStats->twDecreases;
813         mac_stats.twChanges = pMacStats->twChanges;
814         mac_stats.twHighwater = pMacStats->twHighwater;
815         mac_stats.bloomFilterIndex = pMacStats->bloomFilterIndex;
816         memcpy(&pRsp->data.mac_stats, &mac_stats, sizeof(NanMacStats));
817     } else if (stats_type == NAN_STATS_ID_DE_TIMING_SYNC) {
818         NanSyncStats sync_stats;
819         if (message_len != sizeof(NanSyncStats)) {
820             ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n",
821                    __func__, stats_type, message_len, sizeof(NanSyncStats));
822             return;
823         }
824         FwNanSyncStats *pSyncStats = (FwNanSyncStats *)rspBuf;
825 
826         sync_stats.currTsf = pSyncStats->currTsf;
827         sync_stats.myRank = pSyncStats->myRank;
828         sync_stats.currAmRank = pSyncStats->currAmRank;
829         sync_stats.lastAmRank = pSyncStats->lastAmRank;
830         sync_stats.currAmBTT = pSyncStats->currAmBTT;
831         sync_stats.lastAmBTT = pSyncStats->lastAmBTT;
832         sync_stats.currAmHopCount = pSyncStats->currAmHopCount;
833         sync_stats.currRole = pSyncStats->currRole;
834         sync_stats.currClusterId = pSyncStats->currClusterId;
835 
836         sync_stats.timeSpentInCurrRole = pSyncStats->timeSpentInCurrRole;
837         sync_stats.totalTimeSpentAsMaster = pSyncStats->totalTimeSpentAsMaster;
838         sync_stats.totalTimeSpentAsNonMasterSync =
839                             pSyncStats->totalTimeSpentAsNonMasterSync;
840         sync_stats.totalTimeSpentAsNonMasterNonSync =
841                             pSyncStats->totalTimeSpentAsNonMasterNonSync;
842         sync_stats.transitionsToAnchorMaster =
843                             pSyncStats->transitionsToAnchorMaster;
844         sync_stats.transitionsToMaster =
845                             pSyncStats->transitionsToMaster;
846         sync_stats.transitionsToNonMasterSync =
847                             pSyncStats->transitionsToNonMasterSync;
848         sync_stats.transitionsToNonMasterNonSync =
849                             pSyncStats->transitionsToNonMasterNonSync;
850         sync_stats.amrUpdateCount = pSyncStats->amrUpdateCount;
851         sync_stats.amrUpdateRankChangedCount =
852                             pSyncStats->amrUpdateRankChangedCount;
853         sync_stats.amrUpdateBTTChangedCount =
854                             pSyncStats->amrUpdateBTTChangedCount;
855         sync_stats.amrUpdateHcChangedCount =
856                             pSyncStats->amrUpdateHcChangedCount;
857         sync_stats.amrUpdateNewDeviceCount =
858                             pSyncStats->amrUpdateNewDeviceCount;
859         sync_stats.amrExpireCount = pSyncStats->amrExpireCount;
860         sync_stats.mergeCount = pSyncStats->mergeCount;
861         sync_stats.beaconsAboveHcLimit = pSyncStats->beaconsAboveHcLimit;
862         sync_stats.beaconsBelowRssiThresh = pSyncStats->beaconsBelowRssiThresh;
863         sync_stats.beaconsIgnoredNoSpace = pSyncStats->beaconsIgnoredNoSpace;
864         sync_stats.beaconsForOurCluster = pSyncStats->beaconsForOtherCluster;
865         sync_stats.beaconsForOtherCluster = pSyncStats->beaconsForOtherCluster;
866         sync_stats.beaconCancelRequests = pSyncStats->beaconCancelRequests;
867         sync_stats.beaconCancelFailures = pSyncStats->beaconCancelFailures;
868         sync_stats.beaconUpdateRequests = pSyncStats->beaconUpdateRequests;
869         sync_stats.beaconUpdateFailures = pSyncStats->beaconUpdateFailures;
870         sync_stats.syncBeaconTxAttempts = pSyncStats->syncBeaconTxAttempts;
871         sync_stats.syncBeaconTxFailures = pSyncStats->syncBeaconTxFailures;
872         sync_stats.discBeaconTxAttempts = pSyncStats->discBeaconTxAttempts;
873         sync_stats.discBeaconTxFailures = pSyncStats->discBeaconTxFailures;
874         sync_stats.amHopCountExpireCount = pSyncStats->amHopCountExpireCount;
875         sync_stats.ndpChannelFreq = pSyncStats->ndpChannelFreq;
876         sync_stats.ndpChannelFreq2 = pSyncStats->ndpChannelFreq2;
877         sync_stats.schedUpdateChannelFreq = pSyncStats->schedUpdateChannelFreq;
878         memcpy(&pRsp->data.sync_stats, &sync_stats, sizeof(NanSyncStats));
879     } else if (stats_type == NAN_STATS_ID_DE) {
880         NanDeStats de_stats;
881         if (message_len != sizeof(NanDeStats)) {
882             ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n",
883                    __func__, stats_type, message_len, sizeof(NanDeStats));
884             return;
885         }
886         FwNanDeStats *pDeStats = (FwNanDeStats *)rspBuf;
887 
888         de_stats.validErrorRspMsgs = pDeStats->validErrorRspMsgs;
889         de_stats.validTransmitFollowupReqMsgs =
890                         pDeStats->validTransmitFollowupReqMsgs;
891         de_stats.validTransmitFollowupRspMsgs =
892                         pDeStats->validTransmitFollowupRspMsgs;
893         de_stats.validFollowupIndMsgs =
894                         pDeStats->validFollowupIndMsgs;
895         de_stats.validConfigurationReqMsgs =
896                         pDeStats->validConfigurationReqMsgs;
897         de_stats.validConfigurationRspMsgs =
898                         pDeStats->validConfigurationRspMsgs;
899         de_stats.validStatsReqMsgs = pDeStats->validStatsReqMsgs;
900         de_stats.validStatsRspMsgs = pDeStats->validStatsRspMsgs;
901         de_stats.validEnableReqMsgs = pDeStats->validEnableReqMsgs;
902         de_stats.validEnableRspMsgs = pDeStats->validEnableRspMsgs;
903         de_stats.validDisableReqMsgs = pDeStats->validDisableReqMsgs;
904         de_stats.validDisableRspMsgs = pDeStats->validDisableRspMsgs;
905         de_stats.validDisableIndMsgs = pDeStats->validDisableIndMsgs;
906         de_stats.validEventIndMsgs = pDeStats->validEventIndMsgs;
907         de_stats.validTcaReqMsgs = pDeStats->validTcaReqMsgs;
908         de_stats.validTcaRspMsgs = pDeStats->validTcaRspMsgs;
909         de_stats.validTcaIndMsgs = pDeStats->validTcaIndMsgs;
910         de_stats.invalidTransmitFollowupReqMsgs =
911                             pDeStats->invalidTransmitFollowupReqMsgs;
912         de_stats.invalidConfigurationReqMsgs =
913                             pDeStats->invalidConfigurationReqMsgs;
914         de_stats.invalidStatsReqMsgs = pDeStats->invalidStatsReqMsgs;
915         de_stats.invalidEnableReqMsgs = pDeStats->invalidEnableReqMsgs;
916         de_stats.invalidDisableReqMsgs = pDeStats->invalidDisableReqMsgs;
917         de_stats.invalidTcaReqMsgs = pDeStats->invalidTcaReqMsgs;
918         memcpy(&pRsp->data.de_stats, &de_stats, sizeof(NanDeStats));
919     } else {
920         ALOGE("Unknown stats_type:%d\n", stats_type);
921     }
922 }
923 
handleNdpResponse(NanResponseType ndpCmdType,struct nlattr ** tb_vendor)924 int NanCommand::handleNdpResponse(NanResponseType ndpCmdType,
925                                   struct nlattr **tb_vendor)
926 {
927     //parse the data and call
928     //the response callback handler with the populated
929     //NanResponseMsg
930     NanResponseMsg  rsp_data;
931     transaction_id id;
932 
933     memset(&rsp_data, 0, sizeof(rsp_data));
934 
935     if ((!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) ||
936         (!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE]) ||
937         (!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE]))
938     {
939         ALOGE("%s: QCA_WLAN_VENDOR_ATTR_NDP not found", __FUNCTION__);
940         return WIFI_ERROR_INVALID_ARGS;
941     }
942 
943     id = nla_get_u16(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
944     ALOGD("%s: Transaction id : val %d", __FUNCTION__, id);
945 
946     NanErrorTranslation((NanInternalStatusType)nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE]),
947                         nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE]), &rsp_data, true);
948     rsp_data.response_type = ndpCmdType;
949 
950     if (ndpCmdType == NAN_DP_INITIATOR_RESPONSE)
951     {
952         if (!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID])
953         {
954             ALOGE("%s: QCA_WLAN_VENDOR_ATTR_NDP not found", __FUNCTION__);
955             return WIFI_ERROR_INVALID_ARGS;
956         }
957         rsp_data.body.data_request_response.ndp_instance_id =
958         nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID]);
959     }
960     //Call the NotifyResponse Handler
961     if (mHandler.NotifyResponse) {
962         (*mHandler.NotifyResponse)(id, &rsp_data);
963     }
964     return WIFI_SUCCESS;
965 }
966