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 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 340 void NanCommand::NanErrorTranslation(NanInternalStatusType firmwareErrorRecvd, 341 u32 valueRcvd, 342 void* pResponse) 343 { 344 int i = 0, j = 0; 345 u16 msg_id; /* Based on the message_id in the header determine the Indication type */ 346 NanResponseMsg *pRsp; 347 NanPublishTerminatedInd* pRspInd; 348 NanDisabledInd* pRspdInd; 349 char tlvInfo[NAN_ERROR_STR_LEN]; 350 351 if (isNanResponse()) { 352 pRsp = (NanResponseMsg*)pResponse; 353 for (i = 0; i < (int)(sizeof(errorCodeTranslation)/ sizeof(errorCode)); i++) { 354 if (errorCodeTranslation[i].firmwareError == firmwareErrorRecvd) { 355 pRsp->status = errorCodeTranslation[i].frameworkError; 356 strlcpy(pRsp->nan_error, errorCodeTranslation[i].nan_error, NAN_ERROR_STR_LEN); 357 if (NAN_I_STATUS_INVALID_TLV_TYPE == firmwareErrorRecvd) { 358 for (j = 0; j < (int)(sizeof(tlvToStr)/sizeof(verboseTlv)); j++) { 359 if (tlvToStr[j].tlvType == valueRcvd) { 360 strlcpy(tlvInfo, tlvToStr[i].strTlv, NAN_ERROR_STR_LEN); 361 break; 362 } 363 } 364 } 365 strlcat(pRsp->nan_error, tlvInfo, sizeof(pRsp->nan_error)); 366 break; 367 } 368 } 369 if (i == (int)(sizeof(errorCodeTranslation)/sizeof(errorCode))) { 370 pRsp->status = NAN_STATUS_INTERNAL_FAILURE; 371 strlcpy(pRsp->nan_error, "NAN Discovery engine failure", NAN_ERROR_STR_LEN); 372 } 373 ALOGD("%s: Status: %d Error Info[value %d]: %s", __FUNCTION__, pRsp->status, valueRcvd, pRsp->nan_error); 374 } else { 375 msg_id = getIndicationType(); 376 377 switch(msg_id) { 378 case NAN_INDICATION_PUBLISH_TERMINATED: 379 case NAN_INDICATION_SUBSCRIBE_TERMINATED: 380 case NAN_INDICATION_SELF_TRANSMIT_FOLLOWUP: 381 pRspInd = (NanPublishTerminatedInd*)pResponse; 382 for (i = 0; i < (int)(sizeof(errorCodeTranslation)/ sizeof(errorCode)); i++) { 383 if (errorCodeTranslation[i].firmwareError == firmwareErrorRecvd) { 384 pRspInd->reason = errorCodeTranslation[i].frameworkError; 385 strlcpy(pRspInd->nan_reason, errorCodeTranslation[i].nan_error, NAN_ERROR_STR_LEN); 386 break; 387 } 388 } 389 if (i == (int)(sizeof(errorCodeTranslation)/sizeof(errorCode))) { 390 pRspInd->reason = NAN_STATUS_INTERNAL_FAILURE; 391 strlcpy(pRspInd->nan_reason, "NAN Discovery engine failure", NAN_ERROR_STR_LEN); 392 } 393 ALOGD("%s: Status: %d Error Info[value %d]: %s", __FUNCTION__, pRspInd->reason, valueRcvd, pRspInd->nan_reason); 394 break; 395 case NAN_INDICATION_DISABLED: 396 pRspdInd = (NanDisabledInd*)pResponse; 397 for (i = 0; i < (int)(sizeof(errorCodeTranslation)/ sizeof(errorCode)); i++) { 398 if (errorCodeTranslation[i].firmwareError == firmwareErrorRecvd) { 399 pRspdInd->reason = errorCodeTranslation[i].frameworkError; 400 strlcpy(pRspdInd->nan_reason, errorCodeTranslation[i].nan_error, NAN_ERROR_STR_LEN); 401 break; 402 } 403 } 404 if (i == (int)(sizeof(errorCodeTranslation)/sizeof(errorCode))) { 405 pRspdInd->reason = NAN_STATUS_INTERNAL_FAILURE; 406 strlcpy(pRspdInd->nan_reason, "NAN Discovery engine failure", NAN_ERROR_STR_LEN); 407 } 408 ALOGD("%s: Status: %d Error Info[value %d]: %s", __FUNCTION__, pRspdInd->reason, valueRcvd, pRspdInd->nan_reason); 409 break; 410 } 411 } 412 } 413 414 int NanCommand::getNanResponse(transaction_id *id, NanResponseMsg *pRsp) 415 { 416 if (mNanVendorEvent == NULL || pRsp == NULL) { 417 ALOGE("NULL check failed"); 418 return WIFI_ERROR_INVALID_ARGS; 419 } 420 421 NanMsgHeader *pHeader = (NanMsgHeader *)mNanVendorEvent; 422 423 switch (pHeader->msgId) { 424 case NAN_MSG_ID_ERROR_RSP: 425 { 426 pNanErrorRspMsg pFwRsp = \ 427 (pNanErrorRspMsg)mNanVendorEvent; 428 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 429 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 430 pRsp->response_type = NAN_RESPONSE_ERROR; 431 break; 432 } 433 case NAN_MSG_ID_CONFIGURATION_RSP: 434 { 435 pNanConfigurationRspMsg pFwRsp = \ 436 (pNanConfigurationRspMsg)mNanVendorEvent; 437 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 438 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 439 pRsp->response_type = NAN_RESPONSE_CONFIG; 440 } 441 break; 442 case NAN_MSG_ID_PUBLISH_SERVICE_CANCEL_RSP: 443 { 444 pNanPublishServiceCancelRspMsg pFwRsp = \ 445 (pNanPublishServiceCancelRspMsg)mNanVendorEvent; 446 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 447 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 448 pRsp->response_type = NAN_RESPONSE_PUBLISH_CANCEL; 449 pRsp->body.publish_response.publish_id = \ 450 pFwRsp->fwHeader.handle; 451 break; 452 } 453 case NAN_MSG_ID_PUBLISH_SERVICE_RSP: 454 { 455 pNanPublishServiceRspMsg pFwRsp = \ 456 (pNanPublishServiceRspMsg)mNanVendorEvent; 457 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 458 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 459 pRsp->response_type = NAN_RESPONSE_PUBLISH; 460 pRsp->body.publish_response.publish_id = \ 461 pFwRsp->fwHeader.handle; 462 break; 463 } 464 case NAN_MSG_ID_SUBSCRIBE_SERVICE_RSP: 465 { 466 pNanSubscribeServiceRspMsg pFwRsp = \ 467 (pNanSubscribeServiceRspMsg)mNanVendorEvent; 468 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 469 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 470 pRsp->response_type = NAN_RESPONSE_SUBSCRIBE; 471 pRsp->body.subscribe_response.subscribe_id = \ 472 pFwRsp->fwHeader.handle; 473 } 474 break; 475 case NAN_MSG_ID_SUBSCRIBE_SERVICE_CANCEL_RSP: 476 { 477 pNanSubscribeServiceCancelRspMsg pFwRsp = \ 478 (pNanSubscribeServiceCancelRspMsg)mNanVendorEvent; 479 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 480 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 481 pRsp->response_type = NAN_RESPONSE_SUBSCRIBE_CANCEL; 482 pRsp->body.subscribe_response.subscribe_id = \ 483 pFwRsp->fwHeader.handle; 484 break; 485 } 486 case NAN_MSG_ID_TRANSMIT_FOLLOWUP_RSP: 487 { 488 pNanTransmitFollowupRspMsg pFwRsp = \ 489 (pNanTransmitFollowupRspMsg)mNanVendorEvent; 490 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 491 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 492 pRsp->response_type = NAN_RESPONSE_TRANSMIT_FOLLOWUP; 493 break; 494 } 495 case NAN_MSG_ID_STATS_RSP: 496 { 497 pNanStatsRspMsg pFwRsp = \ 498 (pNanStatsRspMsg)mNanVendorEvent; 499 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 500 NanErrorTranslation((NanInternalStatusType)pFwRsp->statsRspParams.status, 501 pFwRsp->statsRspParams.value, pRsp); 502 pRsp->response_type = NAN_RESPONSE_STATS; 503 pRsp->body.stats_response.stats_type = \ 504 (NanStatsType)pFwRsp->statsRspParams.statsType; 505 ALOGV("%s: stats_type:%d",__func__, 506 pRsp->body.stats_response.stats_type); 507 u8 *pInputTlv = pFwRsp->ptlv; 508 NanTlv outputTlv; 509 memset(&outputTlv, 0, sizeof(outputTlv)); 510 u16 readLen = 0; 511 int remainingLen = (mNanDataLen - \ 512 (sizeof(NanMsgHeader) + sizeof(NanStatsRspParams))); 513 if (remainingLen > 0) { 514 readLen = NANTLV_ReadTlv(pInputTlv, &outputTlv); 515 ALOGV("%s: Remaining Len:%d readLen:%d type:%d length:%d", 516 __func__, remainingLen, readLen, outputTlv.type, 517 outputTlv.length); 518 if (outputTlv.length <= \ 519 sizeof(pRsp->body.stats_response.data)) { 520 handleNanStatsResponse(pRsp->body.stats_response.stats_type, 521 (char *)outputTlv.value, 522 &pRsp->body.stats_response, 523 outputTlv.length); 524 } 525 } else 526 ALOGV("%s: No TLV's present",__func__); 527 break; 528 } 529 case NAN_MSG_ID_ENABLE_RSP: 530 { 531 pNanEnableRspMsg pFwRsp = \ 532 (pNanEnableRspMsg)mNanVendorEvent; 533 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 534 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 535 pRsp->response_type = NAN_RESPONSE_ENABLED; 536 break; 537 } 538 case NAN_MSG_ID_DISABLE_RSP: 539 { 540 pNanDisableRspMsg pFwRsp = \ 541 (pNanDisableRspMsg)mNanVendorEvent; 542 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 543 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, 0, pRsp); 544 pRsp->response_type = NAN_RESPONSE_DISABLED; 545 break; 546 } 547 case NAN_MSG_ID_TCA_RSP: 548 { 549 pNanTcaRspMsg pFwRsp = \ 550 (pNanTcaRspMsg)mNanVendorEvent; 551 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 552 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 553 pRsp->response_type = NAN_RESPONSE_TCA; 554 break; 555 } 556 case NAN_MSG_ID_BEACON_SDF_RSP: 557 { 558 pNanBeaconSdfPayloadRspMsg pFwRsp = \ 559 (pNanBeaconSdfPayloadRspMsg)mNanVendorEvent; 560 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 561 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, 0, pRsp); 562 pRsp->response_type = NAN_RESPONSE_BEACON_SDF_PAYLOAD; 563 break; 564 } 565 case NAN_MSG_ID_CAPABILITIES_RSP: 566 { 567 pNanCapabilitiesRspMsg pFwRsp = \ 568 (pNanCapabilitiesRspMsg)mNanVendorEvent; 569 *id = (transaction_id)pFwRsp->fwHeader.transactionId; 570 NanErrorTranslation((NanInternalStatusType)pFwRsp->status, pFwRsp->value, pRsp); 571 pRsp->response_type = NAN_GET_CAPABILITIES; 572 pRsp->body.nan_capabilities.max_concurrent_nan_clusters = \ 573 pFwRsp->max_concurrent_nan_clusters; 574 pRsp->body.nan_capabilities.max_publishes = \ 575 pFwRsp->max_publishes; 576 pRsp->body.nan_capabilities.max_subscribes = \ 577 pFwRsp->max_subscribes; 578 pRsp->body.nan_capabilities.max_service_name_len = \ 579 pFwRsp->max_service_name_len; 580 pRsp->body.nan_capabilities.max_match_filter_len = \ 581 pFwRsp->max_match_filter_len; 582 pRsp->body.nan_capabilities.max_total_match_filter_len = \ 583 pFwRsp->max_total_match_filter_len; 584 pRsp->body.nan_capabilities.max_service_specific_info_len = \ 585 pFwRsp->max_service_specific_info_len; 586 pRsp->body.nan_capabilities.max_vsa_data_len = \ 587 pFwRsp->max_vsa_data_len; 588 pRsp->body.nan_capabilities.max_mesh_data_len = \ 589 pFwRsp->max_mesh_data_len; 590 pRsp->body.nan_capabilities.max_ndi_interfaces = \ 591 pFwRsp->max_ndi_interfaces; 592 pRsp->body.nan_capabilities.max_ndp_sessions = \ 593 pFwRsp->max_ndp_sessions; 594 pRsp->body.nan_capabilities.max_app_info_len = \ 595 pFwRsp->max_app_info_len; 596 pRsp->body.nan_capabilities.max_queued_transmit_followup_msgs = \ 597 pFwRsp->max_queued_transmit_followup_msgs; 598 pRsp->body.nan_capabilities.ndp_supported_bands = \ 599 pFwRsp->ndp_supported_bands; 600 pRsp->body.nan_capabilities.cipher_suites_supported = \ 601 pFwRsp->cipher_suites_supported; 602 pRsp->body.nan_capabilities.max_scid_len = \ 603 pFwRsp->max_scid_len; 604 pRsp->body.nan_capabilities.is_ndp_security_supported = \ 605 pFwRsp->is_ndp_security_supported; 606 pRsp->body.nan_capabilities.max_sdea_service_specific_info_len = \ 607 pFwRsp->max_sdea_service_specific_info_len; 608 pRsp->body.nan_capabilities.max_subscribe_address = \ 609 pFwRsp->max_subscribe_address; 610 break; 611 } 612 default: 613 return -1; 614 } 615 return 0; 616 } 617 618 int NanCommand::handleNanResponse() 619 { 620 //parse the data and call 621 //the response callback handler with the populated 622 //NanResponseMsg 623 NanResponseMsg rsp_data; 624 int ret; 625 transaction_id id; 626 627 ALOGV("handleNanResponse called %p", this); 628 memset(&rsp_data, 0, sizeof(rsp_data)); 629 //get the rsp_data 630 ret = getNanResponse(&id, &rsp_data); 631 632 ALOGI("handleNanResponse ret:%d status:%u value:%s response_type:%u", 633 ret, rsp_data.status, rsp_data.nan_error, rsp_data.response_type); 634 if (ret == 0 && (rsp_data.response_type == NAN_RESPONSE_STATS) && 635 (mStaParam != NULL) && 636 (rsp_data.body.stats_response.stats_type == NAN_STATS_ID_DE_TIMING_SYNC)) { 637 /* 638 Fill the staParam with appropriate values and return from here. 639 No need to call NotifyResponse as the request is for getting the 640 STA response 641 */ 642 NanSyncStats *pSyncStats = &rsp_data.body.stats_response.data.sync_stats; 643 mStaParam->master_rank = pSyncStats->myRank; 644 mStaParam->master_pref = (pSyncStats->myRank & 0xFF00000000000000) >> 56; 645 mStaParam->random_factor = (pSyncStats->myRank & 0x00FF000000000000) >> 48; 646 mStaParam->hop_count = pSyncStats->currAmHopCount; 647 mStaParam->beacon_transmit_time = pSyncStats->currAmBTT; 648 mStaParam->ndp_channel_freq = pSyncStats->ndpChannelFreq; 649 650 ALOGI("%s:0x%02x master_pref 0x%02x random_factor 0x%02x hop_count %u Channel", 651 __func__, mStaParam->master_pref, mStaParam->random_factor, 652 mStaParam->hop_count, mStaParam->ndp_channel_freq); 653 654 return ret; 655 } 656 //Call the NotifyResponse Handler 657 if (ret == 0 && mHandler.NotifyResponse) { 658 (*mHandler.NotifyResponse)(id, &rsp_data); 659 } 660 return ret; 661 } 662 663 void NanCommand::handleNanStatsResponse(NanStatsType stats_type, 664 char *rspBuf, 665 NanStatsResponse *pRsp, 666 u32 message_len) 667 { 668 if (stats_type == NAN_STATS_ID_DE_PUBLISH) { 669 NanPublishStats publish_stats; 670 if (message_len != sizeof(NanPublishStats)) { 671 ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n", 672 __func__, stats_type, message_len, sizeof(NanPublishStats)); 673 return; 674 } 675 FwNanPublishStats *pPubStats = (FwNanPublishStats *)rspBuf; 676 677 publish_stats.validPublishServiceReqMsgs = 678 pPubStats->validPublishServiceReqMsgs; 679 publish_stats.validPublishServiceRspMsgs = 680 pPubStats->validPublishServiceRspMsgs; 681 publish_stats.validPublishServiceCancelReqMsgs = 682 pPubStats->validPublishServiceCancelReqMsgs; 683 publish_stats.validPublishServiceCancelRspMsgs = 684 pPubStats->validPublishServiceCancelRspMsgs; 685 publish_stats.validPublishRepliedIndMsgs = 686 pPubStats->validPublishRepliedIndMsgs; 687 publish_stats.validPublishTerminatedIndMsgs = 688 pPubStats->validPublishTerminatedIndMsgs; 689 publish_stats.validActiveSubscribes = pPubStats->validActiveSubscribes; 690 publish_stats.validMatches = pPubStats->validMatches; 691 publish_stats.validFollowups = pPubStats->validFollowups; 692 publish_stats.invalidPublishServiceReqMsgs = 693 pPubStats->invalidPublishServiceReqMsgs; 694 publish_stats.invalidPublishServiceCancelReqMsgs = 695 pPubStats->invalidPublishServiceCancelReqMsgs; 696 publish_stats.invalidActiveSubscribes = 697 pPubStats->invalidActiveSubscribes; 698 publish_stats.invalidMatches = pPubStats->invalidMatches; 699 publish_stats.invalidFollowups = pPubStats->invalidFollowups; 700 publish_stats.publishCount = pPubStats->publishCount; 701 publish_stats.publishNewMatchCount = pPubStats->publishNewMatchCount; 702 publish_stats.pubsubGlobalNewMatchCount = 703 pPubStats->pubsubGlobalNewMatchCount; 704 memcpy(&pRsp->data, &publish_stats, sizeof(NanPublishStats)); 705 } else if (stats_type == NAN_STATS_ID_DE_SUBSCRIBE) { 706 NanSubscribeStats sub_stats; 707 if (message_len != sizeof(NanSubscribeStats)) { 708 ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n", 709 __func__, stats_type, message_len, sizeof(NanSubscribeStats)); 710 return; 711 } 712 FwNanSubscribeStats *pSubStats = (FwNanSubscribeStats *)rspBuf; 713 714 sub_stats.validSubscribeServiceReqMsgs = 715 pSubStats->validSubscribeServiceReqMsgs; 716 sub_stats.validSubscribeServiceRspMsgs = 717 pSubStats->validSubscribeServiceRspMsgs; 718 sub_stats.validSubscribeServiceCancelReqMsgs = 719 pSubStats->validSubscribeServiceCancelReqMsgs; 720 sub_stats.validSubscribeServiceCancelRspMsgs = 721 pSubStats->validSubscribeServiceCancelRspMsgs; 722 sub_stats.validSubscribeTerminatedIndMsgs = 723 pSubStats->validSubscribeTerminatedIndMsgs; 724 sub_stats.validSubscribeMatchIndMsgs = 725 pSubStats->validSubscribeMatchIndMsgs; 726 sub_stats.validSubscribeUnmatchIndMsgs = 727 pSubStats->validSubscribeUnmatchIndMsgs; 728 sub_stats.validSolicitedPublishes = 729 pSubStats->validSolicitedPublishes; 730 sub_stats.validMatches = pSubStats->validMatches; 731 sub_stats.validFollowups = pSubStats->validFollowups; 732 sub_stats.invalidSubscribeServiceReqMsgs = 733 pSubStats->invalidSubscribeServiceReqMsgs; 734 sub_stats.invalidSubscribeServiceCancelReqMsgs = 735 pSubStats->invalidSubscribeServiceCancelReqMsgs; 736 sub_stats.invalidSubscribeFollowupReqMsgs = 737 pSubStats->invalidSubscribeFollowupReqMsgs; 738 sub_stats.invalidSolicitedPublishes = 739 pSubStats->invalidSolicitedPublishes; 740 sub_stats.invalidMatches = pSubStats->invalidMatches; 741 sub_stats.invalidFollowups = pSubStats->invalidFollowups; 742 sub_stats.subscribeCount = pSubStats->subscribeCount; 743 sub_stats.bloomFilterIndex = pSubStats->bloomFilterIndex; 744 sub_stats.subscribeNewMatchCount = pSubStats->subscribeNewMatchCount; 745 sub_stats.pubsubGlobalNewMatchCount = 746 pSubStats->pubsubGlobalNewMatchCount; 747 memcpy(&pRsp->data, &sub_stats, sizeof(NanSubscribeStats)); 748 } else if (stats_type == NAN_STATS_ID_DE_DW) { 749 NanDWStats dw_stats; 750 if (message_len != sizeof(NanDWStats)) { 751 ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n", 752 __func__, stats_type, message_len, sizeof(NanDWStats)); 753 return; 754 } 755 FwNanMacStats *pMacStats = (FwNanMacStats *)rspBuf; 756 757 dw_stats.validFrames = pMacStats->validFrames; 758 dw_stats.validActionFrames = pMacStats->validActionFrames; 759 dw_stats.validBeaconFrames = pMacStats->validBeaconFrames; 760 dw_stats.ignoredActionFrames = pMacStats->ignoredActionFrames; 761 dw_stats.invalidFrames = pMacStats->invalidFrames; 762 dw_stats.invalidActionFrames = pMacStats->invalidActionFrames; 763 dw_stats.invalidBeaconFrames = pMacStats->invalidBeaconFrames; 764 dw_stats.invalidMacHeaders = pMacStats->invalidMacHeaders; 765 dw_stats.invalidPafHeaders = pMacStats->invalidPafHeaders; 766 dw_stats.nonNanBeaconFrames = pMacStats->nonNanBeaconFrames; 767 dw_stats.earlyActionFrames = pMacStats->earlyActionFrames; 768 dw_stats.inDwActionFrames = pMacStats->inDwActionFrames; 769 dw_stats.lateActionFrames = pMacStats->lateActionFrames; 770 dw_stats.framesQueued = pMacStats->framesQueued; 771 dw_stats.totalTRSpUpdates = pMacStats->totalTRSpUpdates; 772 dw_stats.completeByTRSp = pMacStats->completeByTRSp; 773 dw_stats.completeByTp75DW = pMacStats->completeByTp75DW; 774 dw_stats.completeByTendDW = pMacStats->completeByTendDW; 775 dw_stats.lateActionFramesTx = pMacStats->lateActionFramesTx; 776 memcpy(&pRsp->data, &dw_stats, sizeof(NanDWStats)); 777 } else if (stats_type == NAN_STATS_ID_DE_MAC) { 778 NanMacStats mac_stats; 779 if (message_len != sizeof(NanMacStats)) { 780 ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n", 781 __func__, stats_type, message_len, sizeof(NanMacStats)); 782 return; 783 } 784 FwNanMacStats *pMacStats = (FwNanMacStats *)rspBuf; 785 786 mac_stats.validFrames = pMacStats->validFrames; 787 mac_stats.validActionFrames = pMacStats->validActionFrames; 788 mac_stats.validBeaconFrames = pMacStats->validBeaconFrames; 789 mac_stats.ignoredActionFrames = pMacStats->ignoredActionFrames; 790 mac_stats.invalidFrames = pMacStats->invalidFrames; 791 mac_stats.invalidActionFrames = pMacStats->invalidActionFrames; 792 mac_stats.invalidBeaconFrames = pMacStats->invalidBeaconFrames; 793 mac_stats.invalidMacHeaders = pMacStats->invalidMacHeaders; 794 mac_stats.invalidPafHeaders = pMacStats->invalidPafHeaders; 795 mac_stats.nonNanBeaconFrames = pMacStats->nonNanBeaconFrames; 796 mac_stats.earlyActionFrames = pMacStats->earlyActionFrames; 797 mac_stats.inDwActionFrames = pMacStats->inDwActionFrames; 798 mac_stats.lateActionFrames = pMacStats->lateActionFrames; 799 mac_stats.framesQueued = pMacStats->framesQueued; 800 mac_stats.totalTRSpUpdates = pMacStats->totalTRSpUpdates; 801 mac_stats.completeByTRSp = pMacStats->completeByTRSp; 802 mac_stats.completeByTp75DW = pMacStats->completeByTp75DW; 803 mac_stats.completeByTendDW = pMacStats->completeByTendDW; 804 mac_stats.lateActionFramesTx = pMacStats->lateActionFramesTx; 805 mac_stats.twIncreases = pMacStats->twIncreases; 806 mac_stats.twDecreases = pMacStats->twDecreases; 807 mac_stats.twChanges = pMacStats->twChanges; 808 mac_stats.twHighwater = pMacStats->twHighwater; 809 mac_stats.bloomFilterIndex = pMacStats->bloomFilterIndex; 810 memcpy(&pRsp->data, &mac_stats, sizeof(NanMacStats)); 811 } else if (stats_type == NAN_STATS_ID_DE_TIMING_SYNC) { 812 NanSyncStats sync_stats; 813 if (message_len != sizeof(NanSyncStats)) { 814 ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n", 815 __func__, stats_type, message_len, sizeof(NanSyncStats)); 816 return; 817 } 818 FwNanSyncStats *pSyncStats = (FwNanSyncStats *)rspBuf; 819 820 sync_stats.currTsf = pSyncStats->currTsf; 821 sync_stats.myRank = pSyncStats->myRank; 822 sync_stats.currAmRank = pSyncStats->currAmRank; 823 sync_stats.lastAmRank = pSyncStats->lastAmRank; 824 sync_stats.currAmBTT = pSyncStats->currAmBTT; 825 sync_stats.lastAmBTT = pSyncStats->lastAmBTT; 826 sync_stats.currAmHopCount = pSyncStats->currAmHopCount; 827 sync_stats.currRole = pSyncStats->currRole; 828 sync_stats.currClusterId = pSyncStats->currClusterId; 829 830 sync_stats.timeSpentInCurrRole = pSyncStats->timeSpentInCurrRole; 831 sync_stats.totalTimeSpentAsMaster = pSyncStats->totalTimeSpentAsMaster; 832 sync_stats.totalTimeSpentAsNonMasterSync = 833 pSyncStats->totalTimeSpentAsNonMasterSync; 834 sync_stats.totalTimeSpentAsNonMasterNonSync = 835 pSyncStats->totalTimeSpentAsNonMasterNonSync; 836 sync_stats.transitionsToAnchorMaster = 837 pSyncStats->transitionsToAnchorMaster; 838 sync_stats.transitionsToMaster = 839 pSyncStats->transitionsToMaster; 840 sync_stats.transitionsToNonMasterSync = 841 pSyncStats->transitionsToNonMasterSync; 842 sync_stats.transitionsToNonMasterNonSync = 843 pSyncStats->transitionsToNonMasterNonSync; 844 sync_stats.amrUpdateCount = pSyncStats->amrUpdateCount; 845 sync_stats.amrUpdateRankChangedCount = 846 pSyncStats->amrUpdateRankChangedCount; 847 sync_stats.amrUpdateBTTChangedCount = 848 pSyncStats->amrUpdateBTTChangedCount; 849 sync_stats.amrUpdateHcChangedCount = 850 pSyncStats->amrUpdateHcChangedCount; 851 sync_stats.amrUpdateNewDeviceCount = 852 pSyncStats->amrUpdateNewDeviceCount; 853 sync_stats.amrExpireCount = pSyncStats->amrExpireCount; 854 sync_stats.mergeCount = pSyncStats->mergeCount; 855 sync_stats.beaconsAboveHcLimit = pSyncStats->beaconsAboveHcLimit; 856 sync_stats.beaconsBelowRssiThresh = pSyncStats->beaconsBelowRssiThresh; 857 sync_stats.beaconsIgnoredNoSpace = pSyncStats->beaconsIgnoredNoSpace; 858 sync_stats.beaconsForOurCluster = pSyncStats->beaconsForOtherCluster; 859 sync_stats.beaconsForOtherCluster = pSyncStats->beaconsForOtherCluster; 860 sync_stats.beaconCancelRequests = pSyncStats->beaconCancelRequests; 861 sync_stats.beaconCancelFailures = pSyncStats->beaconCancelFailures; 862 sync_stats.beaconUpdateRequests = pSyncStats->beaconUpdateRequests; 863 sync_stats.beaconUpdateFailures = pSyncStats->beaconUpdateFailures; 864 sync_stats.syncBeaconTxAttempts = pSyncStats->syncBeaconTxAttempts; 865 sync_stats.syncBeaconTxFailures = pSyncStats->syncBeaconTxFailures; 866 sync_stats.discBeaconTxAttempts = pSyncStats->discBeaconTxAttempts; 867 sync_stats.discBeaconTxFailures = pSyncStats->discBeaconTxFailures; 868 sync_stats.amHopCountExpireCount = pSyncStats->amHopCountExpireCount; 869 sync_stats.ndpChannelFreq = pSyncStats->ndpChannelFreq; 870 memcpy(&pRsp->data, &sync_stats, sizeof(NanSyncStats)); 871 } else if (stats_type == NAN_STATS_ID_DE) { 872 NanDeStats de_stats; 873 if (message_len != sizeof(NanDeStats)) { 874 ALOGE("%s: stats_type = %d invalid stats length = %u expected length = %zu\n", 875 __func__, stats_type, message_len, sizeof(NanDeStats)); 876 return; 877 } 878 FwNanDeStats *pDeStats = (FwNanDeStats *)rspBuf; 879 880 de_stats.validErrorRspMsgs = pDeStats->validErrorRspMsgs; 881 de_stats.validTransmitFollowupReqMsgs = 882 pDeStats->validTransmitFollowupReqMsgs; 883 de_stats.validTransmitFollowupRspMsgs = 884 pDeStats->validTransmitFollowupRspMsgs; 885 de_stats.validFollowupIndMsgs = 886 pDeStats->validFollowupIndMsgs; 887 de_stats.validConfigurationReqMsgs = 888 pDeStats->validConfigurationReqMsgs; 889 de_stats.validConfigurationRspMsgs = 890 pDeStats->validConfigurationRspMsgs; 891 de_stats.validStatsReqMsgs = pDeStats->validStatsReqMsgs; 892 de_stats.validStatsRspMsgs = pDeStats->validStatsRspMsgs; 893 de_stats.validEnableReqMsgs = pDeStats->validEnableReqMsgs; 894 de_stats.validEnableRspMsgs = pDeStats->validEnableRspMsgs; 895 de_stats.validDisableReqMsgs = pDeStats->validDisableReqMsgs; 896 de_stats.validDisableRspMsgs = pDeStats->validDisableRspMsgs; 897 de_stats.validDisableIndMsgs = pDeStats->validDisableIndMsgs; 898 de_stats.validEventIndMsgs = pDeStats->validEventIndMsgs; 899 de_stats.validTcaReqMsgs = pDeStats->validTcaReqMsgs; 900 de_stats.validTcaRspMsgs = pDeStats->validTcaRspMsgs; 901 de_stats.validTcaIndMsgs = pDeStats->validTcaIndMsgs; 902 de_stats.invalidTransmitFollowupReqMsgs = 903 pDeStats->invalidTransmitFollowupReqMsgs; 904 de_stats.invalidConfigurationReqMsgs = 905 pDeStats->invalidConfigurationReqMsgs; 906 de_stats.invalidStatsReqMsgs = pDeStats->invalidStatsReqMsgs; 907 de_stats.invalidEnableReqMsgs = pDeStats->invalidEnableReqMsgs; 908 de_stats.invalidDisableReqMsgs = pDeStats->invalidDisableReqMsgs; 909 de_stats.invalidTcaReqMsgs = pDeStats->invalidTcaReqMsgs; 910 memcpy(&pRsp->data, &de_stats, sizeof(NanDeStats)); 911 } else { 912 ALOGE("Unknown stats_type:%d\n", stats_type); 913 } 914 } 915 916 int NanCommand::handleNdpResponse(NanResponseType ndpCmdType, 917 struct nlattr **tb_vendor) 918 { 919 //parse the data and call 920 //the response callback handler with the populated 921 //NanResponseMsg 922 NanResponseMsg rsp_data; 923 transaction_id id; 924 925 memset(&rsp_data, 0, sizeof(rsp_data)); 926 927 if ((!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) || 928 (!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE]) || 929 (!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE])) 930 { 931 ALOGE("%s: QCA_WLAN_VENDOR_ATTR_NDP not found", __FUNCTION__); 932 return WIFI_ERROR_INVALID_ARGS; 933 } 934 935 id = nla_get_u16(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]); 936 ALOGD("%s: Transaction id : val %d", __FUNCTION__, id); 937 938 NanErrorTranslation((NanInternalStatusType)nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE]), 939 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE]), &rsp_data); 940 rsp_data.response_type = ndpCmdType; 941 942 if (ndpCmdType == NAN_DP_INITIATOR_RESPONSE) 943 { 944 if (!tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID]) 945 { 946 ALOGE("%s: QCA_WLAN_VENDOR_ATTR_NDP not found", __FUNCTION__); 947 return WIFI_ERROR_INVALID_ARGS; 948 } 949 rsp_data.body.data_request_response.ndp_instance_id = 950 nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID]); 951 } 952 //Call the NotifyResponse Handler 953 if (mHandler.NotifyResponse) { 954 (*mHandler.NotifyResponse)(id, &rsp_data); 955 } 956 return WIFI_SUCCESS; 957 } 958