summaryrefslogtreecommitdiff
path: root/wcn6740/qcwcn/wifi_hal/wifihal_vendor.cpp
blob: 4837e63f062ab999cbc5867565ceda9c810cf5ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/*
 * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.
 *     * Neither the name of The Linux Foundation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 * Changes from Qualcomm Innovation Center are provided under the following license:

 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 * SPDX-License-Identifier: BSD-3-Clause-Clear
 */

#include "sync.h"

#define LOG_TAG  "WifiHAL"

#include <utils/Log.h>

#include "wifi_hal.h"
#include "common.h"
#include "cpp_bindings.h"
#include "wifihal_vendorcommand.h"

#define MAX_INFO 1
//Singleton Static Instance
NUDStatsCommand* NUDStatsCommand::mNUDStatsCommandInstance  = NULL;

// This function implements creation of Vendor command
// For NUDStats just call base Vendor command create
wifi_error NUDStatsCommand::create() {
    wifi_error ret = mMsg.create(NL80211_CMD_VENDOR, 0, 0);
    if (ret != WIFI_SUCCESS) {
        return ret;
    }
    // insert the oui in the msg
    ret = mMsg.put_u32(NL80211_ATTR_VENDOR_ID, mVendor_id);
    if (ret != WIFI_SUCCESS)
        goto out;

    // insert the subcmd in the msg
    ret = mMsg.put_u32(NL80211_ATTR_VENDOR_SUBCMD, mSubcmd);
    if (ret != WIFI_SUCCESS)
        goto out;

out:
    return ret;
}

NUDStatsCommand::NUDStatsCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd)
        : WifiVendorCommand(handle, id, vendor_id, subcmd)
{
    memset(&mStats, 0,sizeof(nud_stats));
    mpktInfo = NULL;
    mnumStats = 0;
}

NUDStatsCommand::~NUDStatsCommand()
{
    mNUDStatsCommandInstance = NULL;
}

NUDStatsCommand* NUDStatsCommand::instance(wifi_handle handle)
{
    if (handle == NULL) {
        ALOGE("Interface Handle is invalid");
        return NULL;
    }
    if (mNUDStatsCommandInstance == NULL) {
        mNUDStatsCommandInstance = new NUDStatsCommand(handle, 0,
                OUI_QCA,
                QCA_NL80211_VENDOR_SUBCMD_NUD_STATS_SET);
        return mNUDStatsCommandInstance;
    }
    else
    {
        if (handle != getWifiHandle(mNUDStatsCommandInstance->mInfo))
        {
            /* upper layer must have cleaned up the handle and reinitialized,
               so we need to update the same */
            ALOGE("Handle different, update the handle");
            mNUDStatsCommandInstance->mInfo = (hal_info *)handle;
        }
    }
    return mNUDStatsCommandInstance;
}

void NUDStatsCommand::setSubCmd(u32 subcmd)
{
    mSubcmd = subcmd;
}

void NUDStatsCommand::setHandler(pkt_stats_result_handler handler)
{
    mHandler = handler;
}

wifi_error NUDStatsCommand::requestResponse()
{
    return WifiCommand::requestResponse(mMsg);
}

wifi_error NUDStatsCommand::notifyResponse()
{
    wifi_error ret = WIFI_SUCCESS;

    if (mHandler.on_pkt_stats_results) {
        mHandler.on_pkt_stats_results(&mStats, mnumStats,
                                      mpktInfo);
    } else {
        ret = WIFI_ERROR_INVALID_ARGS;
    }
    return ret;
}

int NUDStatsCommand::handleResponse(WifiEvent &reply)
{
    wifi_error status = WIFI_ERROR_NONE;
    WifiVendorCommand::handleResponse(reply);

    // Parse the vendordata and get the attribute

    switch(mSubcmd)
    {
        case QCA_NL80211_VENDOR_SUBCMD_NUD_STATS_GET:
        {
            struct nlattr *tb_vendor[QCA_ATTR_NUD_STATS_GET_MAX + 1];
            nud_stats *stats = &mStats;

            memset(stats, 0, sizeof(nud_stats));
            nla_parse(tb_vendor, QCA_ATTR_NUD_STATS_GET_MAX,
                      (struct nlattr *)mVendorData, mDataLen, NULL);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_FROM_NETDEV])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_FROM_NETDEV"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_req_count_from_netdev = nla_get_u16(tb_vendor[
                            QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_FROM_NETDEV]);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_TO_LOWER_MAC])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_TO_LOWER_MAC"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_req_count_to_lower_mac = nla_get_u16(tb_vendor[
                            QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_TO_LOWER_MAC]);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_REQ_RX_COUNT_BY_LOWER_MAC])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_REQ_RX_COUNT_BY_LOWER_MAC"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_req_rx_count_by_lower_mac = nla_get_u16(tb_vendor[
                            QCA_ATTR_NUD_STATS_ARP_REQ_RX_COUNT_BY_LOWER_MAC]);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_TX_SUCCESS])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_TX_SUCCESS"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_req_count_tx_success = nla_get_u16(tb_vendor[
                            QCA_ATTR_NUD_STATS_ARP_REQ_COUNT_TX_SUCCESS]);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_RSP_RX_COUNT_BY_LOWER_MAC])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_RSP_RX_COUNT_BY_LOWER_MAC"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_rsp_rx_count_by_lower_mac = nla_get_u16(tb_vendor[
                            QCA_ATTR_NUD_STATS_ARP_RSP_RX_COUNT_BY_LOWER_MAC]);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_RSP_RX_COUNT_BY_UPPER_MAC])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_RSP_RX_COUNT_BY_UPPER_MAC"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_rsp_rx_count_by_upper_mac = nla_get_u16(tb_vendor[
                            QCA_ATTR_NUD_STATS_ARP_RSP_RX_COUNT_BY_UPPER_MAC]);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_RSP_COUNT_TO_NETDEV])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_RSP_COUNT_TO_NETDEV"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_rsp_count_to_netdev = nla_get_u16(tb_vendor[
                            QCA_ATTR_NUD_STATS_ARP_RSP_COUNT_TO_NETDEV]);

            if (!tb_vendor[QCA_ATTR_NUD_STATS_ARP_RSP_COUNT_OUT_OF_ORDER_DROP])
            {
                ALOGE("%s: QCA_ATTR_NUD_STATS_ARP_RSP_COUNT_OUT_OF_ORDER_DROP"
                      " not found", __FUNCTION__);
                status = WIFI_ERROR_INVALID_ARGS;
                goto cleanup;
            }
            stats->arp_rsp_count_out_of_order_drop = nla_get_u16(tb_vendor[
                           QCA_ATTR_NUD_STATS_ARP_RSP_COUNT_OUT_OF_ORDER_DROP]);

            if (tb_vendor[QCA_ATTR_NUD_STATS_AP_LINK_ACTIVE])
                stats->ap_link_active = 1;

            if (tb_vendor[QCA_ATTR_NUD_STATS_IS_DAD])
                stats->is_duplicate_addr_detection = 1;

            ALOGV(" req_from_netdev %d count_to_lower :%d"
                  " count_by_lower :%d"
                  " count_tx_succ :%d rsp_count_lower :%d"
                  " rsp_count_upper :%d  rsp_count_netdev :%d"
                  " out_of_order_drop :%d active_aplink %d"
                  " DAD %d ",
                  stats->arp_req_count_from_netdev,
                  stats->arp_req_count_to_lower_mac,
                  stats->arp_req_rx_count_by_lower_mac,
                  stats->arp_req_count_tx_success,
                  stats->arp_rsp_rx_count_by_lower_mac,
                  stats->arp_rsp_rx_count_by_upper_mac,
                  stats->arp_rsp_count_to_netdev,
                  stats->arp_rsp_count_out_of_order_drop,
                  stats->ap_link_active,
                  stats->is_duplicate_addr_detection);

            if (tb_vendor[QCA_ATTR_NUD_STATS_DATA_PKT_STATS]) {
                mNUDStatsCommandInstance->GetPktInfo(tb_vendor);
            }
        }
    }
cleanup:
    if (status == WIFI_ERROR_INVALID_ARGS)
       memset(&mStats,0,sizeof(nud_stats));
       if(mpktInfo != NULL)
         free(mpktInfo);

    return status;
}

void NUDStatsCommand::GetPktInfo(struct nlattr **tbvendor)
{
    struct nlattr *tb;
    int rem;
    cmdData *pkt_stats;
    char ipv6_address[INET6_ADDRSTRLEN];
    cmdData pktstats;
    int nbuff = 0;

    for (tb = (struct nlattr *) nla_data(tbvendor[QCA_ATTR_NUD_STATS_DATA_PKT_STATS]),
         rem = nla_len(tbvendor[QCA_ATTR_NUD_STATS_DATA_PKT_STATS]);
         nla_ok(tb, rem); tb = nla_next(tb, &(rem)))
       {
           struct nlattr *tb2[QCA_ATTR_NUD_DATA_STATS_MAX + 1];
           nla_parse(tb2, QCA_ATTR_NUD_DATA_STATS_MAX,
                     (struct nlattr *) nla_data(tb), nla_len(tb), NULL);

           memset(&pktstats, 0, sizeof(cmdData));

           if (tb2[QCA_ATTR_NUD_STATS_PKT_TYPE])
           {
              pktstats.pkt_Type = nla_get_u32(tb2[QCA_ATTR_NUD_STATS_PKT_TYPE]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_DNS_DOMAIN_NAME])
           {
              pktstats.domain_name = nla_get_string(tb2[QCA_ATTR_NUD_STATS_PKT_DNS_DOMAIN_NAME]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_SRC_PORT])
           {
              pktstats.src_port = nla_get_u32(tb2[QCA_ATTR_NUD_STATS_PKT_SRC_PORT]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_DEST_PORT])
           {
              pktstats.dst_port = nla_get_u32(tb2[QCA_ATTR_NUD_STATS_PKT_DEST_PORT]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_DEST_IPV4])
           {
              pktstats.ipv4_addr.s_addr = nla_get_u32(tb2[QCA_ATTR_NUD_STATS_PKT_DEST_IPV4]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_DEST_IPV6])
           {
              memcpy(pktstats.ipv6_addr, nla_data(tb2[QCA_ATTR_NUD_STATS_PKT_DEST_IPV6]),
                     sizeof(pktstats.ipv6_addr));
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_REQ_COUNT_FROM_NETDEV])
           {
              pktstats.stats.pkt_req_count_from_netdev = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_REQ_COUNT_FROM_NETDEV]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_REQ_COUNT_TO_LOWER_MAC])
           {
              pktstats.stats.pkt_req_count_to_lower_mac = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_REQ_COUNT_TO_LOWER_MAC]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_REQ_RX_COUNT_BY_LOWER_MAC])
           {
              pktstats.stats.pkt_req_rx_count_by_lower_mac = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_REQ_RX_COUNT_BY_LOWER_MAC]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_REQ_COUNT_TX_SUCCESS])
           {
              pktstats.stats.pkt_req_count_tx_success = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_REQ_COUNT_TX_SUCCESS]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_RSP_RX_COUNT_BY_LOWER_MAC])
           {
              pktstats.stats.pkt_rsp_rx_count_by_lower_mac = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_RSP_RX_COUNT_BY_LOWER_MAC]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_RSP_RX_COUNT_BY_UPPER_MAC])
           {
              pktstats.stats.pkt_rsp_rx_count_by_upper_mac = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_RSP_RX_COUNT_BY_UPPER_MAC]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_RSP_COUNT_TO_NETDEV])
           {
              pktstats.stats.pkt_rsp_count_to_netdev = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_RSP_COUNT_TO_NETDEV]);
           }

           if (tb2[QCA_ATTR_NUD_STATS_PKT_RSP_COUNT_OUT_OF_ORDER_DROP])
           {
              pktstats.stats.pkt_rsp_count_out_of_order_drop = nla_get_u16(tb2[
                            QCA_ATTR_NUD_STATS_PKT_RSP_COUNT_OUT_OF_ORDER_DROP]);
           }

           if (inet_ntop(AF_INET6, pktstats.ipv6_addr, ipv6_address,
                         INET6_ADDRSTRLEN) == NULL) {
               ALOGE("%s: failed to convert ipv6 address format", __FUNCTION__);
           }

           ALOGV(" pkt_type %d domain_name :%s"
                 " src_port %d dst_port :%d"
                 " ipv4_address :%x ipv6_address %s"
                 " req_from_netdev %d count_to_lower :%d"
                 " count_by_lower :%d"
                 " count_tx_succ :%d rsp_count_lower :%d"
                 " rsp_count_upper :%d  rsp_count_netdev :%d"
                 " out_of_order_drop :%d ",
                 pktstats.pkt_Type, pktstats.domain_name,
                 pktstats.src_port, pktstats.dst_port,
                 pktstats.ipv4_addr.s_addr, ipv6_address,
                 pktstats.stats.pkt_req_count_from_netdev,
                 pktstats.stats.pkt_req_count_to_lower_mac,
                 pktstats.stats.pkt_req_rx_count_by_lower_mac,
                 pktstats.stats.pkt_req_count_tx_success,
                 pktstats.stats.pkt_rsp_rx_count_by_lower_mac,
                 pktstats.stats.pkt_rsp_rx_count_by_upper_mac,
                 pktstats.stats.pkt_rsp_count_to_netdev,
                 pktstats.stats.pkt_rsp_count_out_of_order_drop);

            if (nbuff == 0)
               pkt_stats = (cmdData *)malloc(sizeof(cmdData));
            else
               pkt_stats = (cmdData *)realloc(pkt_stats,sizeof(cmdData) * (nbuff + 1));

            mpktInfo = pkt_stats;
            if (pkt_stats != NULL) {
                memcpy(&pkt_stats[nbuff], &pktstats,sizeof(cmdData));
                nbuff++;
                mnumStats = nbuff;
            }
       }
}

void NUDStatsCommand::copyStats(nud_stats *stats, cmdData *pktstats)
{
    memcpy(stats, &mStats, sizeof(nud_stats));
    pktstats = mpktInfo;
}

wifi_error wifi_set_nud_stats(wifi_interface_handle iface,
                              u32 gw_addr, cmdData Data)
{
    wifi_error ret;
    NUDStatsCommand *NUDCommand;
    struct nlattr *nl_data,*nl_pktInfo;
    interface_info *iinfo = getIfaceInfo(iface);
    wifi_handle handle = getWifiHandle(iface);
    cmdData mData = Data;
    cmdData pktstats = Data;

    ALOGV("gw_addr : %x", gw_addr);
    NUDCommand = NUDStatsCommand::instance(handle);
    if (NUDCommand == NULL) {
        ALOGE("%s: Error NUDStatsCommand NULL", __FUNCTION__);
        return WIFI_ERROR_INVALID_ARGS;
    }
    NUDCommand->setSubCmd(QCA_NL80211_VENDOR_SUBCMD_NUD_STATS_SET);

    /* create the message */
    ret = NUDCommand->create();
    if (ret != WIFI_SUCCESS)
        goto cleanup;

    ret = NUDCommand->set_iface_id(iinfo->name);
    if (ret != WIFI_SUCCESS)
        goto cleanup;

    /*add the attributes*/
    nl_data = NUDCommand->attr_start(NL80211_ATTR_VENDOR_DATA);
    if (!nl_data)
        goto cleanup;
    /**/
    ret = NUDCommand->put_flag(QCA_ATTR_NUD_STATS_SET_START);

    ret = NUDCommand->put_u32(QCA_ATTR_NUD_STATS_GW_IPV4, gw_addr);
    if (ret != WIFI_SUCCESS)
        goto cleanup;

    if (mData.pkt_Type) {
       /*start the packet info attributes in nested*/
       nl_pktInfo = NUDCommand->attr_start(QCA_ATTR_NUD_STATS_SET_DATA_PKT_INFO);
       if (!nl_pktInfo)
           goto cleanup;
       else {
           ALOGV(" pkt_type %d domain_name :%s"
                 " src_port %d dst_port :%d"
                 " ipv4_address :%x ipv6_address %s",
                 pktstats.pkt_Type, pktstats.domain_name,
                 pktstats.src_port, pktstats.dst_port,
                 pktstats.ipv4_addr.s_addr,pktstats.ipv6_addr);

           for (int i=0; i < MAX_INFO ; i++) {
               /*add the packet type attributes*/
               struct nlattr *tb_tmp;
               tb_tmp = NUDCommand->attr_start(i);

               ret = NUDCommand->put_u32(QCA_ATTR_NUD_STATS_DATA_PKT_INFO_TYPE,mData.pkt_Type);
               if (ret != WIFI_SUCCESS)
                   goto cleanup;

               if (mData.domain_name) {
                   /*add the domain name attributes*/
                   ret = NUDCommand->put_string(QCA_ATTR_NUD_STATS_DATA_PKT_INFO_DNS_DOMAIN_NAME,
                                                mData.domain_name);
                   if (ret != WIFI_SUCCESS)
                       goto cleanup;
               }
               /*add the source port attributes*/
               ret = NUDCommand->put_u32(QCA_ATTR_NUD_STATS_DATA_PKT_INFO_SRC_PORT,
                                         mData.src_port);
               if (ret != WIFI_SUCCESS)
                   goto cleanup;

               /*add the dest port attributes*/
               ret = NUDCommand->put_u32(QCA_ATTR_NUD_STATS_DATA_PKT_INFO_DEST_PORT,
                                         mData.dst_port);
               if (ret != WIFI_SUCCESS)
                   goto cleanup;

               /*add the ipv4 address attributes*/
               ret = NUDCommand->put_u32(QCA_ATTR_NUD_STATS_DATA_PKT_INFO_DEST_IPV4,
                                         mData.ipv4_addr.s_addr);
               if (ret != WIFI_SUCCESS)
                   goto cleanup;

               /*add the ipv6 address attributes*/
               ret = NUDCommand->put_ipv6_addr(QCA_ATTR_NUD_STATS_DATA_PKT_INFO_DEST_IPV6,
                                               mData.ipv6_addr);
               if (ret != WIFI_SUCCESS)
                   goto cleanup;
               NUDCommand->attr_end(tb_tmp);
           }
       }
       NUDCommand->attr_end(nl_pktInfo);
    }
    NUDCommand->attr_end(nl_data);

    ret = NUDCommand->requestResponse();
    if (ret != WIFI_SUCCESS) {
        ALOGE("%s: requestResponse Error:%d",__FUNCTION__, ret);
    }

cleanup:
    return ret;
}


wifi_error wifi_get_nud_stats(wifi_interface_handle iface,
                              pkt_stats_result_handler handler)
{
    wifi_error ret;
    NUDStatsCommand *NUDCommand;
    struct nlattr *nl_data;
    interface_info *iinfo = getIfaceInfo(iface);
    wifi_handle handle = getWifiHandle(iface);

    NUDCommand = NUDStatsCommand::instance(handle);
    if (NUDCommand == NULL) {
        ALOGE("%s: Error NUDStatsCommand NULL", __FUNCTION__);
        return WIFI_ERROR_INVALID_ARGS;
    }
    NUDCommand->setSubCmd(QCA_NL80211_VENDOR_SUBCMD_NUD_STATS_GET);

    NUDCommand->setHandler(handler);

    /* create the message */
    ret = NUDCommand->create();
    if (ret != WIFI_SUCCESS)
        goto cleanup;

    ret = NUDCommand->set_iface_id(iinfo->name);
    if (ret != WIFI_SUCCESS)
        goto cleanup;
    /*add the attributes*/
    nl_data = NUDCommand->attr_start(NL80211_ATTR_VENDOR_DATA);
    if (!nl_data){
        ret = WIFI_ERROR_UNKNOWN;
        goto cleanup;
    }
    /**/
    NUDCommand->attr_end(nl_data);

    ret = NUDCommand->requestResponse();
    if (ret != WIFI_SUCCESS) {
        ALOGE("%s: requestResponse Error:%d",__FUNCTION__, ret);
        goto cleanup;
    }

    ret = NUDCommand->notifyResponse();
    if (ret != WIFI_SUCCESS) {
        ALOGE("%s: requestResponse Error:%d",__FUNCTION__, ret);
        goto cleanup;
    }

cleanup:
    return ret;
}


wifi_error wifi_clear_nud_stats(wifi_interface_handle iface,
                                cmdData Data)
{
    wifi_error ret;
    NUDStatsCommand *NUDCommand;
    struct nlattr *nl_data,*nl_pktInfo;
    interface_info *iinfo = getIfaceInfo(iface);
    wifi_handle handle = getWifiHandle(iface);
    cmdData mData = Data;

    NUDCommand = NUDStatsCommand::instance(handle);
    if (NUDCommand == NULL) {
        ALOGE("%s: Error NUDStatsCommand NULL", __FUNCTION__);
        return WIFI_ERROR_INVALID_ARGS;
    }
    NUDCommand->setSubCmd(QCA_NL80211_VENDOR_SUBCMD_NUD_STATS_SET);

    /* create the message */
    ret = NUDCommand->create();
    if (ret != WIFI_SUCCESS)
        goto cleanup;

    ret = NUDCommand->set_iface_id(iinfo->name);
    if (ret != WIFI_SUCCESS)
        goto cleanup;

    /*add the attributes*/
    nl_data = NUDCommand->attr_start(NL80211_ATTR_VENDOR_DATA);
    if (!nl_data){
        ret = WIFI_ERROR_UNKNOWN;
        goto cleanup;
    }
    if (mData.pkt_Type) {
       /*set the packet info attributes in nested*/
       nl_pktInfo = NUDCommand->attr_start(QCA_ATTR_NUD_STATS_SET_DATA_PKT_INFO);
       if (!nl_pktInfo){
           ret = WIFI_ERROR_UNKNOWN;
           goto cleanup;
       }
       else {
           ALOGV(" %s: pkt_type %d domain_name :%s"
                 " src_port %d dst_port :%d"
                 " ipv4_address :%x ipv6_address %s",
                 __FUNCTION__,mData.pkt_Type, mData.domain_name,
                 mData.src_port, mData.dst_port,
                 mData.ipv4_addr.s_addr,mData.ipv6_addr);

           for (int i=0; i < MAX_INFO ; i++) {
               /*add the packet type attributes*/
               struct nlattr *tb_tmp;
               tb_tmp = NUDCommand->attr_start(i);

               ret = NUDCommand->put_u32(QCA_ATTR_NUD_STATS_DATA_PKT_INFO_TYPE,mData.pkt_Type);
               if (ret != WIFI_SUCCESS)
                   goto cleanup;

               NUDCommand->attr_end(tb_tmp);
           }
       }
       NUDCommand->attr_end(nl_pktInfo);
    }
    NUDCommand->attr_end(nl_data);

    ret = NUDCommand->requestResponse();
    if (ret != WIFI_SUCCESS)
        ALOGE("%s: requestResponse Error:%d",__FUNCTION__, ret);

cleanup:
    return ret;
}