Home | History | Annotate | Download | only in snep
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  NFA SNEP interface to LLCP
     22  *
     23  ******************************************************************************/
     24 #include <string.h>
     25 #include "nfa_api.h"
     26 #include "nfa_sys.h"
     27 #include "nfa_sys_int.h"
     28 #include "nfa_snep_int.h"
     29 #include "nfa_mem_co.h"
     30 
     31 /*****************************************************************************
     32 **  Constants
     33 *****************************************************************************/
     34 
     35 /*******************************************************************************
     36 **
     37 ** Function         NFA_SnepStartDefaultServer
     38 **
     39 ** Description      This function is called to listen to SAP, 0x04 as SNEP default
     40 **                  server ("urn:nfc:sn:snep") on LLCP.
     41 **
     42 **                  NFA_SNEP_DEFAULT_SERVER_STARTED_EVT without data will be returned.
     43 **
     44 ** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
     45 **                  should happen before calling this function
     46 **
     47 ** Returns          NFA_STATUS_OK if successfully initiated
     48 **                  NFA_STATUS_FAILED otherwise
     49 **
     50 *******************************************************************************/
     51 tNFA_STATUS NFA_SnepStartDefaultServer (tNFA_SNEP_CBACK *p_cback)
     52 {
     53     tNFA_SNEP_API_START_DEFAULT_SERVER *p_msg;
     54 
     55     SNEP_TRACE_API0 ("NFA_SnepStartDefaultServer ()");
     56 
     57     if (p_cback == NULL)
     58     {
     59         SNEP_TRACE_ERROR0 ("NFA_SnepStartDefaultServer (): p_cback is NULL");
     60         return (NFA_STATUS_INVALID_PARAM);
     61     }
     62 
     63     if ((p_msg = (tNFA_SNEP_API_START_DEFAULT_SERVER *) GKI_getbuf (sizeof (tNFA_SNEP_API_START_DEFAULT_SERVER))) != NULL)
     64     {
     65         p_msg->hdr.event = NFA_SNEP_API_START_DEFAULT_SERVER_EVT;
     66         p_msg->p_cback   = p_cback;
     67 
     68         nfa_sys_sendmsg (p_msg);
     69 
     70         return (NFA_STATUS_OK);
     71     }
     72 
     73     return (NFA_STATUS_FAILED);
     74 }
     75 
     76 /*******************************************************************************
     77 **
     78 ** Function         NFA_SnepStopDefaultServer
     79 **
     80 ** Description      This function is called to stop SNEP default server on LLCP.
     81 **
     82 **                  NFA_SNEP_DEFAULT_SERVER_STOPPED_EVT without data will be returned.
     83 **
     84 ** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
     85 **                  should happen before calling this function
     86 **
     87 ** Returns          NFA_STATUS_OK if successfully initiated
     88 **                  NFA_STATUS_FAILED otherwise
     89 **
     90 *******************************************************************************/
     91 tNFA_STATUS NFA_SnepStopDefaultServer (tNFA_SNEP_CBACK *p_cback)
     92 {
     93     tNFA_SNEP_API_STOP_DEFAULT_SERVER *p_msg;
     94 
     95     SNEP_TRACE_API0 ("NFA_SnepStopDefaultServer ()");
     96 
     97     if (p_cback == NULL)
     98     {
     99         SNEP_TRACE_ERROR0 ("NFA_SnepStopDefaultServer (): p_cback is NULL");
    100         return (NFA_STATUS_INVALID_PARAM);
    101     }
    102 
    103     if ((p_msg = (tNFA_SNEP_API_STOP_DEFAULT_SERVER *) GKI_getbuf (sizeof (tNFA_SNEP_API_STOP_DEFAULT_SERVER))) != NULL)
    104     {
    105         p_msg->hdr.event = NFA_SNEP_API_STOP_DEFAULT_SERVER_EVT;
    106         p_msg->p_cback   = p_cback;
    107 
    108         nfa_sys_sendmsg (p_msg);
    109 
    110         return (NFA_STATUS_OK);
    111     }
    112 
    113     return (NFA_STATUS_FAILED);
    114 }
    115 
    116 /*******************************************************************************
    117 **
    118 ** Function         NFA_SnepRegisterServer
    119 **
    120 ** Description      This function is called to listen to a SAP as SNEP server.
    121 **
    122 **                  If server_sap is set to NFA_SNEP_ANY_SAP, then NFA will allocate
    123 **                  a SAP between LLCP_LOWER_BOUND_SDP_SAP and LLCP_UPPER_BOUND_SDP_SAP
    124 **
    125 **                  NFC Forum default SNEP server ("urn:nfc:sn:snep") may be launched
    126 **                  by NFA_SnepStartDefaultServer().
    127 **
    128 **                  NFA_SNEP_REG_EVT will be returned with status, handle and service name.
    129 **
    130 ** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
    131 **                  should happen before calling this function
    132 **
    133 ** Returns          NFA_STATUS_OK if successfully initiated
    134 **                  NFA_STATUS_INVALID_PARAM if p_service_name or p_cback is NULL
    135 **                  NFA_STATUS_FAILED otherwise
    136 **
    137 *******************************************************************************/
    138 tNFA_STATUS NFA_SnepRegisterServer (UINT8           server_sap,
    139                                     char            *p_service_name,
    140                                     tNFA_SNEP_CBACK *p_cback)
    141 {
    142     tNFA_SNEP_API_REG_SERVER *p_msg;
    143 
    144     SNEP_TRACE_API2 ("NFA_SnepRegisterServer (): SAP:0x%X, SN:<%s>", server_sap, p_service_name);
    145 
    146     if ((p_service_name == NULL) || (p_cback == NULL))
    147     {
    148         SNEP_TRACE_ERROR0 ("NFA_SnepRegisterServer (): p_service_name or p_cback is NULL");
    149         return (NFA_STATUS_INVALID_PARAM);
    150     }
    151 
    152     if ((p_msg = (tNFA_SNEP_API_REG_SERVER *) GKI_getbuf (sizeof (tNFA_SNEP_API_REG_SERVER))) != NULL)
    153     {
    154         p_msg->hdr.event = NFA_SNEP_API_REG_SERVER_EVT;
    155 
    156         p_msg->server_sap = server_sap;
    157 
    158         BCM_STRNCPY_S (p_msg->service_name, sizeof (p_msg->service_name),
    159                        p_service_name, LLCP_MAX_SN_LEN);
    160         p_msg->service_name[LLCP_MAX_SN_LEN] = 0;
    161 
    162         p_msg->p_cback = p_cback;
    163 
    164         nfa_sys_sendmsg (p_msg);
    165 
    166         return (NFA_STATUS_OK);
    167     }
    168 
    169     return (NFA_STATUS_FAILED);
    170 }
    171 
    172 /*******************************************************************************
    173 **
    174 ** Function         NFA_SnepRegisterClient
    175 **
    176 ** Description      This function is called to register SNEP client.
    177 **                  NFA_SNEP_REG_EVT will be returned with status, handle
    178 **                  and zero-length service name.
    179 **
    180 ** Returns          NFA_STATUS_OK if successfully initiated
    181 **                  NFA_STATUS_INVALID_PARAM if p_cback is NULL
    182 **                  NFA_STATUS_FAILED otherwise
    183 **
    184 *******************************************************************************/
    185 tNFA_STATUS NFA_SnepRegisterClient (tNFA_SNEP_CBACK *p_cback)
    186 {
    187     tNFA_SNEP_API_REG_CLIENT *p_msg;
    188 
    189     SNEP_TRACE_API0 ("NFA_SnepRegisterClient ()");
    190 
    191     if (p_cback == NULL)
    192     {
    193         SNEP_TRACE_ERROR0 ("NFA_SnepRegisterClient (): p_cback is NULL");
    194         return (NFA_STATUS_INVALID_PARAM);
    195     }
    196 
    197     if ((p_msg = (tNFA_SNEP_API_REG_CLIENT *) GKI_getbuf (sizeof (tNFA_SNEP_API_REG_CLIENT))) != NULL)
    198     {
    199         p_msg->hdr.event = NFA_SNEP_API_REG_CLIENT_EVT;
    200 
    201         p_msg->p_cback = p_cback;
    202 
    203         nfa_sys_sendmsg (p_msg);
    204 
    205         return (NFA_STATUS_OK);
    206     }
    207 
    208     return (NFA_STATUS_FAILED);
    209 }
    210 
    211 /*******************************************************************************
    212 **
    213 ** Function         NFA_SnepDeregister
    214 **
    215 ** Description      This function is called to stop listening as SNEP server
    216 **                  or SNEP client. Application shall use reg_handle returned in
    217 **                  NFA_SNEP_REG_EVT.
    218 **
    219 ** Note:            If this function is called to de-register a SNEP server and RF
    220 **                  discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
    221 **                  should happen before calling this function
    222 **
    223 ** Returns          NFA_STATUS_OK if successfully initiated
    224 **                  NFA_STATUS_BAD_HANDLE if handle is not valid
    225 **                  NFA_STATUS_FAILED otherwise
    226 **
    227 *******************************************************************************/
    228 tNFA_STATUS NFA_SnepDeregister (tNFA_HANDLE reg_handle)
    229 {
    230     tNFA_SNEP_API_DEREG *p_msg;
    231     tNFA_HANDLE          xx;
    232 
    233     SNEP_TRACE_API1 ("NFA_SnepDeregister (): reg_handle:0x%X", reg_handle);
    234 
    235     xx = reg_handle & NFA_HANDLE_MASK;
    236 
    237     if (  (xx >= NFA_SNEP_MAX_CONN)
    238         ||(nfa_snep_cb.conn[xx].p_cback == NULL)  )
    239     {
    240         SNEP_TRACE_ERROR0 ("NFA_SnepDeregister (): Handle is invalid or not registered");
    241         return (NFA_STATUS_BAD_HANDLE);
    242     }
    243 
    244     if ((p_msg = (tNFA_SNEP_API_DEREG *) GKI_getbuf (sizeof (tNFA_SNEP_API_DEREG))) != NULL)
    245     {
    246         p_msg->hdr.event = NFA_SNEP_API_DEREG_EVT;
    247 
    248         p_msg->reg_handle = reg_handle;
    249 
    250         nfa_sys_sendmsg (p_msg);
    251 
    252         return (NFA_STATUS_OK);
    253     }
    254 
    255     return (NFA_STATUS_FAILED);
    256 }
    257 
    258 /*******************************************************************************
    259 **
    260 ** Function         NFA_SnepConnect
    261 **
    262 ** Description      This function is called by client to create data link connection
    263 **                  to SNEP server on peer device.
    264 **
    265 **                  Client handle and service name of server to connect shall be provided.
    266 **                  A conn_handle will be returned in NFA_SNEP_CONNECTED_EVT, if
    267 **                  successfully connected. Otherwise NFA_SNEP_DISC_EVT will be returned.
    268 **
    269 ** Returns          NFA_STATUS_OK if successfully initiated
    270 **                  NFA_STATUS_BAD_HANDLE if handle is not valid
    271 **                  NFA_STATUS_INVALID_PARAM if p_service_name or p_cback is NULL
    272 **                  NFA_STATUS_FAILED otherwise
    273 **
    274 *******************************************************************************/
    275 tNFA_STATUS NFA_SnepConnect (tNFA_HANDLE     client_handle,
    276                              char            *p_service_name)
    277 {
    278     tNFA_SNEP_API_CONNECT *p_msg;
    279     tNFA_HANDLE            xx;
    280 
    281     SNEP_TRACE_API1 ("NFA_SnepConnect(): client_handle:0x%X", client_handle);
    282 
    283     xx = client_handle & NFA_HANDLE_MASK;
    284 
    285     if (  (xx >= NFA_SNEP_MAX_CONN)
    286         ||(nfa_snep_cb.conn[xx].p_cback == NULL)
    287         ||(!(nfa_snep_cb.conn[xx].flags & NFA_SNEP_FLAG_CLIENT))  )
    288     {
    289         SNEP_TRACE_ERROR0 ("NFA_SnepConnect (): Client handle is invalid");
    290         return (NFA_STATUS_BAD_HANDLE);
    291     }
    292 
    293     if (p_service_name == NULL)
    294     {
    295         SNEP_TRACE_ERROR0 ("NFA_SnepConnect (): p_service_name is NULL");
    296         return (NFA_STATUS_INVALID_PARAM);
    297     }
    298 
    299     if ((p_msg = (tNFA_SNEP_API_CONNECT*) GKI_getbuf (sizeof (tNFA_SNEP_API_CONNECT))) != NULL)
    300     {
    301         p_msg->hdr.event = NFA_SNEP_API_CONNECT_EVT;
    302 
    303         p_msg->client_handle = client_handle;
    304         BCM_STRNCPY_S (p_msg->service_name, sizeof (p_msg->service_name),
    305                        p_service_name, LLCP_MAX_SN_LEN);
    306         p_msg->service_name[LLCP_MAX_SN_LEN] = 0;
    307 
    308         nfa_sys_sendmsg (p_msg);
    309 
    310         return (NFA_STATUS_OK);
    311     }
    312 
    313     return (NFA_STATUS_FAILED);
    314 }
    315 
    316 /*******************************************************************************
    317 **
    318 ** Function         NFA_SnepGet
    319 **
    320 ** Description      This function is called by client to send GET request.
    321 **
    322 **                  Application shall allocate a buffer and put NDEF message with
    323 **                  desired record type to get from server. NDEF message from server
    324 **                  will be returned in the same buffer with NFA_SNEP_GET_RESP_EVT.
    325 **                  The size of buffer will be used as "Acceptable Length".
    326 **
    327 **                  NFA_SNEP_GET_RESP_EVT or NFA_SNEP_DISC_EVT will be returned
    328 **                  through registered p_cback. Application may free the buffer
    329 **                  after receiving these events.
    330 **
    331 **
    332 ** Returns          NFA_STATUS_OK if successfully initiated
    333 **                  NFA_STATUS_BAD_HANDLE if handle is not valid
    334 **                  NFA_STATUS_FAILED otherwise
    335 **
    336 *******************************************************************************/
    337 tNFA_STATUS NFA_SnepGet (tNFA_HANDLE     conn_handle,
    338                          UINT32          buff_length,
    339                          UINT32          ndef_length,
    340                          UINT8           *p_ndef_buff)
    341 {
    342     tNFA_SNEP_API_GET_REQ *p_msg;
    343     tNFA_HANDLE            xx;
    344 
    345     SNEP_TRACE_API1 ("NFA_SnepGet (): conn_handle:0x%X", conn_handle);
    346 
    347     xx = conn_handle & NFA_HANDLE_MASK;
    348 
    349     if (  (xx >= NFA_SNEP_MAX_CONN)
    350         ||(nfa_snep_cb.conn[xx].p_cback == NULL)
    351         ||(!(nfa_snep_cb.conn[xx].flags & NFA_SNEP_FLAG_CLIENT))  )
    352     {
    353         SNEP_TRACE_ERROR0 ("NFA_SnepGet (): Connection handle is invalid");
    354         return (NFA_STATUS_BAD_HANDLE);
    355     }
    356 
    357     if ((p_msg = (tNFA_SNEP_API_GET_REQ *) GKI_getbuf (sizeof (tNFA_SNEP_API_GET_REQ))) != NULL)
    358     {
    359         p_msg->hdr.event = NFA_SNEP_API_GET_REQ_EVT;
    360 
    361         p_msg->conn_handle = conn_handle;
    362         p_msg->buff_length = buff_length;
    363         p_msg->ndef_length = ndef_length;
    364         p_msg->p_ndef_buff = p_ndef_buff;
    365 
    366         nfa_sys_sendmsg (p_msg);
    367 
    368         return (NFA_STATUS_OK);
    369     }
    370 
    371     return (NFA_STATUS_FAILED);
    372 }
    373 
    374 /*******************************************************************************
    375 **
    376 ** Function         NFA_SnepPut
    377 **
    378 ** Description      This function is called by client to send PUT request.
    379 **
    380 **                  Application shall allocate a buffer and put desired NDEF message
    381 **                  to send to server.
    382 **
    383 **                  NFA_SNEP_PUT_RESP_EVT or NFA_SNEP_DISC_EVT will be returned
    384 **                  through registered p_cback. Application may free the buffer after
    385 **                  receiving these events.
    386 **
    387 ** Returns          NFA_STATUS_OK if successfully initiated
    388 **                  NFA_STATUS_BAD_HANDLE if handle is not valid
    389 **                  NFA_STATUS_FAILED otherwise
    390 **
    391 *******************************************************************************/
    392 tNFA_STATUS NFA_SnepPut (tNFA_HANDLE     conn_handle,
    393                          UINT32          ndef_length,
    394                          UINT8           *p_ndef_buff)
    395 {
    396     tNFA_SNEP_API_PUT_REQ *p_msg;
    397     tNFA_HANDLE            xx;
    398 
    399     SNEP_TRACE_API1 ("NFA_SnepPut (): conn_handle:0x%X", conn_handle);
    400 
    401     xx = conn_handle & NFA_HANDLE_MASK;
    402 
    403     if (  (xx >= NFA_SNEP_MAX_CONN)
    404         ||(nfa_snep_cb.conn[xx].p_cback == NULL)
    405         ||(!(nfa_snep_cb.conn[xx].flags & NFA_SNEP_FLAG_CLIENT))  )
    406     {
    407         SNEP_TRACE_ERROR0 ("NFA_SnepPut (): Connection handle is invalid");
    408         return (NFA_STATUS_BAD_HANDLE);
    409     }
    410 
    411     if ((p_msg = (tNFA_SNEP_API_PUT_REQ *) GKI_getbuf (sizeof (tNFA_SNEP_API_PUT_REQ))) != NULL)
    412     {
    413         p_msg->hdr.event = NFA_SNEP_API_PUT_REQ_EVT;
    414 
    415         p_msg->conn_handle = conn_handle;
    416         p_msg->ndef_length = ndef_length;
    417         p_msg->p_ndef_buff = p_ndef_buff;
    418 
    419         nfa_sys_sendmsg (p_msg);
    420 
    421         return (NFA_STATUS_OK);
    422     }
    423 
    424     return (NFA_STATUS_FAILED);
    425 }
    426 
    427 /*******************************************************************************
    428 **
    429 ** Function         NFA_SnepGetResponse
    430 **
    431 ** Description      This function is called by server to send response of GET request.
    432 **
    433 **                  When server application receives NFA_SNEP_ALLOC_BUFF_EVT,
    434 **                  it shall allocate a buffer for incoming NDEF message and
    435 **                  pass the pointer within callback context. This buffer will be
    436 **                  returned with NFA_SNEP_GET_REQ_EVT after receiving complete
    437 **                  NDEF message. If buffer is not allocated, NFA_SNEP_RESP_CODE_NOT_FOUND
    438 **                  (Note:There is no proper response code for this case)
    439 **                  or NFA_SNEP_RESP_CODE_REJECT will be sent to client.
    440 **
    441 **                  Server application shall provide conn_handle which is received in
    442 **                  NFA_SNEP_GET_REQ_EVT.
    443 **
    444 **                  Server application shall allocate a buffer and put NDEF message if
    445 **                  response code is NFA_SNEP_RESP_CODE_SUCCESS. Otherwise, ndef_length
    446 **                  shall be set to zero.
    447 **
    448 **                  NFA_SNEP_GET_RESP_CMPL_EVT or NFA_SNEP_DISC_EVT will be returned
    449 **                  through registered callback function. Application may free
    450 **                  the buffer after receiving these events.
    451 **
    452 ** Returns          NFA_STATUS_OK if successfully initiated
    453 **                  NFA_STATUS_BAD_HANDLE if handle is not valid
    454 **                  NFA_STATUS_FAILED otherwise
    455 **
    456 *******************************************************************************/
    457 tNFA_STATUS NFA_SnepGetResponse (tNFA_HANDLE         conn_handle,
    458                                  tNFA_SNEP_RESP_CODE resp_code,
    459                                  UINT32              ndef_length,
    460                                  UINT8               *p_ndef_buff)
    461 {
    462     tNFA_SNEP_API_GET_RESP *p_msg;
    463     tNFA_HANDLE            xx;
    464 
    465     SNEP_TRACE_API1 ("NFA_SnepGetResponse (): conn_handle:0x%X", conn_handle);
    466 
    467     xx = conn_handle & NFA_HANDLE_MASK;
    468 
    469     if (  (xx >= NFA_SNEP_MAX_CONN)
    470         ||(nfa_snep_cb.conn[xx].p_cback == NULL)
    471         ||(!(nfa_snep_cb.conn[xx].flags & NFA_SNEP_FLAG_SERVER))  )
    472     {
    473         SNEP_TRACE_ERROR0 ("NFA_SnepGetResponse (): Handle is invalid");
    474         return (NFA_STATUS_BAD_HANDLE);
    475     }
    476 
    477     if ((p_msg = (tNFA_SNEP_API_GET_RESP *) GKI_getbuf (sizeof (tNFA_SNEP_API_GET_RESP))) != NULL)
    478     {
    479         p_msg->hdr.event = NFA_SNEP_API_GET_RESP_EVT;
    480 
    481         p_msg->conn_handle = conn_handle;
    482         p_msg->resp_code   = resp_code;
    483         p_msg->ndef_length = ndef_length;
    484         p_msg->p_ndef_buff = p_ndef_buff;
    485 
    486         nfa_sys_sendmsg (p_msg);
    487 
    488         return (NFA_STATUS_OK);
    489     }
    490 
    491     return (NFA_STATUS_FAILED);
    492 }
    493 
    494 
    495 /*******************************************************************************
    496 **
    497 ** Function         NFA_SnepPutResponse
    498 **
    499 ** Description      This function is called by server to send response of PUT request.
    500 **
    501 **                  When server application receives NFA_SNEP_ALLOC_BUFF_EVT,
    502 **                  it shall allocate a buffer for incoming NDEF message and
    503 **                  pass the pointer within callback context. This buffer will be
    504 **                  returned with NFA_SNEP_PUT_REQ_EVT after receiving complete
    505 **                  NDEF message.  If buffer is not allocated, NFA_SNEP_RESP_CODE_REJECT
    506 **                  will be sent to client or NFA will discard request and send
    507 **                  NFA_SNEP_RESP_CODE_SUCCESS (Note:There is no proper response code for
    508 **                  this case).
    509 **
    510 **                  Server application shall provide conn_handle which is received in
    511 **                  NFA_SNEP_PUT_REQ_EVT.
    512 **
    513 **                  NFA_SNEP_DISC_EVT will be returned through registered callback
    514 **                  function when client disconnects data link connection.
    515 **
    516 ** Returns          NFA_STATUS_OK if successfully initiated
    517 **                  NFA_STATUS_BAD_HANDLE if handle is not valid
    518 **                  NFA_STATUS_FAILED otherwise
    519 **
    520 *******************************************************************************/
    521 tNFA_STATUS NFA_SnepPutResponse (tNFA_HANDLE         conn_handle,
    522                                  tNFA_SNEP_RESP_CODE resp_code)
    523 {
    524     tNFA_SNEP_API_PUT_RESP *p_msg;
    525     tNFA_HANDLE            xx;
    526 
    527     SNEP_TRACE_API1 ("NFA_SnepPutResponse (): conn_handle:0x%X", conn_handle);
    528 
    529     xx = conn_handle & NFA_HANDLE_MASK;
    530 
    531     if (  (xx >= NFA_SNEP_MAX_CONN)
    532         ||(nfa_snep_cb.conn[xx].p_cback == NULL)
    533         ||(!(nfa_snep_cb.conn[xx].flags & NFA_SNEP_FLAG_SERVER))  )
    534     {
    535         SNEP_TRACE_ERROR0 ("NFA_SnepPutResponse (): Handle is invalid");
    536         return (NFA_STATUS_BAD_HANDLE);
    537     }
    538 
    539     if ((p_msg = (tNFA_SNEP_API_PUT_RESP *) GKI_getbuf (sizeof (tNFA_SNEP_API_PUT_RESP))) != NULL)
    540     {
    541         p_msg->hdr.event = NFA_SNEP_API_PUT_RESP_EVT;
    542 
    543         p_msg->conn_handle = conn_handle;
    544         p_msg->resp_code   = resp_code;
    545 
    546         nfa_sys_sendmsg (p_msg);
    547 
    548         return (NFA_STATUS_OK);
    549     }
    550 
    551     return (NFA_STATUS_FAILED);
    552 }
    553 
    554 /*******************************************************************************
    555 **
    556 ** Function         NFA_SnepDisconnect
    557 **
    558 ** Description      This function is called to disconnect data link connection.
    559 **                  discard any pending data if flush is set to TRUE
    560 **
    561 **                  Client application shall provide conn_handle in NFA_SNEP_GET_RESP_EVT
    562 **                  or NFA_SNEP_PUT_RESP_EVT.
    563 **
    564 **                  Server application shall provide conn_handle in NFA_SNEP_GET_REQ_EVT
    565 **                  or NFA_SNEP_PUT_REQ_EVT.
    566 **
    567 **                  NFA_SNEP_DISC_EVT will be returned
    568 **
    569 ** Returns          NFA_STATUS_OK if successfully initiated
    570 **                  NFA_STATUS_BAD_HANDLE if handle is not valid
    571 **                  NFA_STATUS_FAILED otherwise
    572 **
    573 *******************************************************************************/
    574 tNFA_STATUS NFA_SnepDisconnect (tNFA_HANDLE conn_handle, BOOLEAN flush)
    575 {
    576     tNFA_SNEP_API_DISCONNECT *p_msg;
    577     tNFA_HANDLE              xx;
    578 
    579     SNEP_TRACE_API2 ("NFA_SnepDisconnect (): conn_handle:0x%X, flush=%d", conn_handle, flush);
    580 
    581     xx = conn_handle & NFA_HANDLE_MASK;
    582 
    583     if (  (xx >= NFA_SNEP_MAX_CONN)
    584         ||(nfa_snep_cb.conn[xx].p_cback == NULL))
    585     {
    586         SNEP_TRACE_ERROR0 ("NFA_SnepDisconnect (): Handle is invalid");
    587         return (NFA_STATUS_BAD_HANDLE);
    588     }
    589 
    590     if ((p_msg = (tNFA_SNEP_API_DISCONNECT *) GKI_getbuf (sizeof (tNFA_SNEP_API_DISCONNECT))) != NULL)
    591     {
    592         p_msg->hdr.event   = NFA_SNEP_API_DISCONNECT_EVT;
    593         p_msg->conn_handle = conn_handle;
    594         p_msg->flush       = flush;
    595 
    596         nfa_sys_sendmsg (p_msg);
    597 
    598         return (NFA_STATUS_OK);
    599     }
    600 
    601     return (NFA_STATUS_FAILED);
    602 }
    603 
    604 /*******************************************************************************
    605 **
    606 ** Function         NFA_SnepSetTraceLevel
    607 **
    608 ** Description      This function sets the trace level for SNEP.  If called with
    609 **                  a value of 0xFF, it simply returns the current trace level.
    610 **
    611 ** Returns          The new or current trace level
    612 **
    613 *******************************************************************************/
    614 UINT8 NFA_SnepSetTraceLevel (UINT8 new_level)
    615 {
    616     if (new_level != 0xFF)
    617         nfa_snep_cb.trace_level = new_level;
    618 
    619     return (nfa_snep_cb.trace_level);
    620 }
    621