Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 NXP Semiconductors
      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 <phNfcTypes.h>
     18 #include <phLibNfc.h>
     19 #include <phLibNfc_Internal.h>
     20 #include <phFriNfc_Llcp.h>
     21 #include <phFriNfc_LlcpTransport.h>
     22 
     23 /* ---------------------------- Internal macros -------------------------------- */
     24 
     25 #ifndef STATIC_DISABLE
     26 #define STATIC static
     27 #else
     28 #define STATIC
     29 #endif
     30 
     31 /* ----------------------- Internal functions headers -------------------------- */
     32 
     33 STATIC
     34 NFCSTATUS static_CheckState();
     35 
     36 STATIC
     37 NFCSTATUS static_CheckDevice(phLibNfc_Handle hRemoteDevice);
     38 
     39 STATIC
     40 void phLibNfc_Llcp_CheckLlcp_Cb(void *pContext,NFCSTATUS status);
     41 
     42 /* --------------------------- Internal functions ------------------------------ */
     43 
     44 STATIC NFCSTATUS static_CheckState()
     45 {
     46    /* Check if the global context is set */
     47    if(gpphLibContext == NULL)
     48    {
     49       return NFCSTATUS_NOT_INITIALISED;
     50    }
     51 
     52    /* Check if initialized */
     53    if(gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown)
     54    {
     55       return NFCSTATUS_NOT_INITIALISED;
     56    }
     57 
     58    /* Check if shutting down */
     59    if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
     60    {
     61       return NFCSTATUS_SHUTDOWN;
     62    }
     63 
     64    return NFCSTATUS_SUCCESS;
     65 }
     66 
     67 STATIC NFCSTATUS static_CheckDevice(phLibNfc_Handle hRemoteDevice)
     68 {
     69    phLibNfc_sRemoteDevInformation_t*   psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice;
     70 
     71    /* If local device is the Initiator (remote is Target),
     72     * check if connection is correct
     73     */
     74    if (psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Target)
     75    {
     76       /* Check if any device connected */
     77       if(gpphLibContext->Connected_handle == 0)
     78       {
     79          return NFCSTATUS_TARGET_NOT_CONNECTED;
     80       }
     81 
     82       /* Check if handle corresponds to connected one */
     83       if(hRemoteDevice != gpphLibContext->Connected_handle)
     84       {
     85          return NFCSTATUS_INVALID_HANDLE;
     86       }
     87    }
     88 
     89    /* Check if previous callback is pending or if remote peer is not LLCP compliant */
     90    if ((gpphLibContext->status.GenCb_pending_status == TRUE) ||
     91             (gpphLibContext->llcp_cntx.bIsLlcp == FALSE))
     92    {
     93       return NFCSTATUS_REJECTED;
     94    }
     95 
     96    return NFCSTATUS_SUCCESS;
     97 }
     98 
     99 /* ---------------------------- Public functions ------------------------------- */
    100 
    101 NFCSTATUS phLibNfc_Mgt_SetLlcp_ConfigParams( phLibNfc_Llcp_sLinkParameters_t* pConfigInfo,
    102                                             pphLibNfc_RspCb_t                pConfigRspCb,
    103                                             void*                            pContext
    104                                             )
    105 {
    106    NFCSTATUS      result;
    107    phNfc_sData_t  sGeneralBytesBuffer;
    108    phLibNfc_sNfcIPCfg_t sNfcIPCfg;
    109    const uint8_t  pMagicBuffer[] = { 0x46, 0x66, 0x6D };
    110 
    111    /* State checking */
    112    result = static_CheckState();
    113    if (result != NFCSTATUS_SUCCESS)
    114    {
    115       return result;
    116    }
    117 
    118    /* Parameters checking */
    119    if ((pConfigInfo == NULL) || (pConfigRspCb == NULL))
    120    {
    121       return NFCSTATUS_INVALID_PARAMETER;
    122    }
    123 
    124    /* Save the config for later use */
    125    memcpy( &gpphLibContext->llcp_cntx.sLocalParams,
    126            pConfigInfo,
    127            sizeof(phLibNfc_Llcp_sLinkParameters_t) );
    128 
    129    /* Copy magic number in NFCIP General Bytes */
    130    memcpy(sNfcIPCfg.generalBytes, pMagicBuffer, sizeof(pMagicBuffer));
    131    sNfcIPCfg.generalBytesLength = sizeof(pMagicBuffer);
    132 
    133    /* Encode link parameters in TLV to configure P2P General Bytes */
    134    sGeneralBytesBuffer.buffer = sNfcIPCfg.generalBytes + sizeof(pMagicBuffer);
    135    sGeneralBytesBuffer.length = sizeof(sNfcIPCfg.generalBytes) - sizeof(pMagicBuffer);
    136    result = phFriNfc_Llcp_EncodeLinkParams( &sGeneralBytesBuffer,
    137                                             pConfigInfo,
    138                                             PHFRINFC_LLCP_VERSION);
    139    if (result != NFCSTATUS_SUCCESS)
    140    {
    141       return PHNFCSTATUS(result);
    142    }
    143    sNfcIPCfg.generalBytesLength += (uint8_t)sGeneralBytesBuffer.length;
    144 
    145    /* Set the P2P general bytes */
    146    result = phLibNfc_Mgt_SetP2P_ConfigParams(&sNfcIPCfg, pConfigRspCb, pContext);
    147    return PHNFCSTATUS(result);
    148 }
    149 
    150 NFCSTATUS phLibNfc_Llcp_CheckLlcp( phLibNfc_Handle              hRemoteDevice,
    151                                    pphLibNfc_ChkLlcpRspCb_t     pCheckLlcp_RspCb,
    152                                    pphLibNfc_LlcpLinkStatusCb_t pLink_Cb,
    153                                    void*                        pContext
    154                                    )
    155 {
    156    NFCSTATUS                           result;
    157    phLibNfc_sRemoteDevInformation_t*   psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice;
    158 
    159    /* State checking */
    160    result = static_CheckState();
    161    if (result != NFCSTATUS_SUCCESS)
    162    {
    163       return result;
    164    }
    165 
    166    /* Parameters checking */
    167    if ((hRemoteDevice == 0)       ||
    168        (pCheckLlcp_RspCb == NULL) ||
    169        (pLink_Cb == NULL))
    170    {
    171       return NFCSTATUS_INVALID_PARAMETER;
    172    }
    173 
    174    /* If local device is the Initiator (remote is Target),
    175     * check if connection is correct
    176     */
    177    if (psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Target)
    178    {
    179       /* Check if any device connected */
    180       if(gpphLibContext->Connected_handle == 0)
    181       {
    182          return NFCSTATUS_TARGET_NOT_CONNECTED;
    183       }
    184 
    185       /* Check if handle corresponds to connected one */
    186       if(hRemoteDevice != gpphLibContext->Connected_handle)
    187       {
    188          return NFCSTATUS_INVALID_HANDLE;
    189       }
    190    }
    191 
    192    /* Resets the LLCP LLC component */
    193    result = phFriNfc_Llcp_Reset( &gpphLibContext->llcp_cntx.sLlcpContext,
    194                                  gpphLibContext->psOverHalCtxt,
    195                                  &gpphLibContext->llcp_cntx.sLocalParams,
    196                                  gpphLibContext->llcp_cntx.pRxBuffer,
    197                                  sizeof(gpphLibContext->llcp_cntx.pRxBuffer),
    198                                  gpphLibContext->llcp_cntx.pTxBuffer,
    199                                  sizeof(gpphLibContext->llcp_cntx.pTxBuffer),
    200                                  pLink_Cb,
    201                                  pContext);
    202    if (result != NFCSTATUS_SUCCESS)
    203    {
    204       return PHNFCSTATUS(result);
    205    }
    206 
    207    /* Resets the LLCP Transport component */
    208    result = phFriNfc_LlcpTransport_Reset( &gpphLibContext->llcp_cntx.sLlcpTransportContext,
    209                                           &gpphLibContext->llcp_cntx.sLlcpContext );
    210    if (result != NFCSTATUS_SUCCESS)
    211    {
    212       return result;
    213    }
    214 
    215    /* Prepare callback */
    216    gpphLibContext->CBInfo.pClientLlcpCheckRespCb = pCheckLlcp_RspCb;
    217    gpphLibContext->CBInfo.pClientLlcpCheckRespCntx = pContext;
    218 
    219    /* Update state */
    220    result = phLibNfc_UpdateNextState(gpphLibContext, eLibNfcHalStateTransaction);
    221    if (result != NFCSTATUS_SUCCESS)
    222    {
    223       return result;
    224    }
    225 
    226    /* Call the component function */
    227    result = phFriNfc_Llcp_ChkLlcp( &gpphLibContext->llcp_cntx.sLlcpContext,
    228                                    psRemoteDevInfo,
    229                                    phLibNfc_Llcp_CheckLlcp_Cb,
    230                                    gpphLibContext
    231                                    );
    232    result = PHNFCSTATUS(result);
    233    if (result == NFCSTATUS_PENDING)
    234    {
    235       gpphLibContext->status.GenCb_pending_status = TRUE;
    236    }
    237    else if (result == NFCSTATUS_SUCCESS)
    238    {
    239       /* Nothing to do */
    240    }
    241    else if (result != NFCSTATUS_FAILED)
    242    {
    243       result = NFCSTATUS_TARGET_LOST;
    244    }
    245 
    246    return result;
    247 }
    248 
    249 /* Response callback for phLibNfc_Ndef_CheckNdef */
    250 STATIC
    251 void phLibNfc_Llcp_CheckLlcp_Cb(void *pContext, NFCSTATUS status)
    252 {
    253    phLibNfc_LibContext_t      *pLibNfc_Ctxt = (phLibNfc_LibContext_t *)pContext;
    254    NFCSTATUS                  RetStatus = NFCSTATUS_SUCCESS;
    255    pphLibNfc_ChkLlcpRspCb_t   pClientCb = NULL;
    256    void                       *pClientContext = NULL;
    257 
    258    if(pLibNfc_Ctxt != gpphLibContext)
    259    {
    260       /*wrong context returned from below layer*/
    261       phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
    262    }
    263    else
    264    {
    265       if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
    266       {
    267          /*shutdown called before completion of check Ndef, allow shutdown to happen */
    268          phLibNfc_Pending_Shutdown();
    269          RetStatus = NFCSTATUS_SHUTDOWN;
    270       }
    271       else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateRelease)
    272       {
    273          RetStatus = NFCSTATUS_ABORTED;
    274       }
    275       else
    276       {
    277          if(status == NFCSTATUS_SUCCESS)
    278          {
    279             /* Remote peer is LLCP compliant */
    280             gpphLibContext->llcp_cntx.bIsLlcp = TRUE;
    281          }
    282          else if(PHNFCSTATUS(status)== NFCSTATUS_FAILED)
    283          {
    284             RetStatus = NFCSTATUS_FAILED;
    285             gpphLibContext->llcp_cntx.bIsLlcp = FALSE;
    286          }
    287          else
    288          {
    289             RetStatus = NFCSTATUS_TARGET_LOST;
    290          }
    291       }
    292 
    293       /* Update the current state */
    294       gpphLibContext->status.GenCb_pending_status = FALSE;
    295       phLibNfc_UpdateCurState(RetStatus,gpphLibContext);
    296 
    297       /* Copy callback details */
    298       pClientCb = gpphLibContext->CBInfo.pClientLlcpCheckRespCb;
    299       pClientContext = gpphLibContext->CBInfo.pClientLlcpCheckRespCntx;
    300 
    301       /* Reset saved callback */
    302       gpphLibContext->CBInfo.pClientCkNdefCb = NULL;
    303       gpphLibContext->CBInfo.pClientCkNdefCntx = NULL;
    304 
    305       /* Trigger the callback */
    306       if(pClientCb != NULL)
    307       {
    308          pClientCb(pClientContext,RetStatus);
    309       }
    310    }
    311 }
    312 
    313 NFCSTATUS phLibNfc_Llcp_Activate( phLibNfc_Handle hRemoteDevice )
    314 {
    315    NFCSTATUS result;
    316 
    317    /* State checking */
    318    result = static_CheckState();
    319    if (result != NFCSTATUS_SUCCESS)
    320    {
    321       return result;
    322    }
    323 
    324    /* Parameters checking */
    325    if (hRemoteDevice == 0)
    326    {
    327       return NFCSTATUS_INVALID_PARAMETER;
    328    }
    329 
    330    /* Check device */
    331    result = static_CheckDevice(hRemoteDevice);
    332    if (result != NFCSTATUS_SUCCESS)
    333    {
    334       return result;
    335    }
    336 
    337    /* Start activation */
    338    result = phFriNfc_Llcp_Activate(&gpphLibContext->llcp_cntx.sLlcpContext);
    339 
    340    return PHNFCSTATUS(result);
    341 }
    342 
    343 NFCSTATUS phLibNfc_Llcp_Deactivate( phLibNfc_Handle  hRemoteDevice )
    344 {
    345    NFCSTATUS result;
    346 
    347    /* State checking */
    348    result = static_CheckState();
    349    if (result != NFCSTATUS_SUCCESS)
    350    {
    351       return result;
    352    }
    353 
    354    /* Parameters checking */
    355    if (hRemoteDevice == 0)
    356    {
    357       return NFCSTATUS_INVALID_PARAMETER;
    358    }
    359 
    360    /* Check device */
    361    result = static_CheckDevice(hRemoteDevice);
    362    if (result != NFCSTATUS_SUCCESS)
    363    {
    364       return result;
    365    }
    366 
    367    /* Start deactivation */
    368    result = phFriNfc_Llcp_Deactivate(&gpphLibContext->llcp_cntx.sLlcpContext);
    369 
    370    return PHNFCSTATUS(result);
    371 }
    372 
    373 NFCSTATUS phLibNfc_Llcp_GetLocalInfo( phLibNfc_Handle                  hRemoteDevice,
    374                                       phLibNfc_Llcp_sLinkParameters_t* pConfigInfo
    375                                       )
    376 {
    377    NFCSTATUS result;
    378 
    379    /* State checking */
    380    result = static_CheckState();
    381    if (result != NFCSTATUS_SUCCESS)
    382    {
    383       return result;
    384    }
    385 
    386    /* Parameters checking */
    387    if ((hRemoteDevice == 0) ||
    388        (pConfigInfo == NULL))
    389    {
    390       return NFCSTATUS_INVALID_PARAMETER;
    391    }
    392 
    393    /* Check device */
    394    result = static_CheckDevice(hRemoteDevice);
    395    if (result != NFCSTATUS_SUCCESS)
    396    {
    397       return result;
    398    }
    399 
    400    /* Get local infos */
    401    result = phFriNfc_Llcp_GetLocalInfo(&gpphLibContext->llcp_cntx.sLlcpContext, pConfigInfo);
    402 
    403    return PHNFCSTATUS(result);
    404 }
    405 
    406 NFCSTATUS phLibNfc_Llcp_GetRemoteInfo( phLibNfc_Handle                    hRemoteDevice,
    407                                        phLibNfc_Llcp_sLinkParameters_t*   pConfigInfo
    408                                        )
    409 {
    410    NFCSTATUS result;
    411 
    412    /* State checking */
    413    result = static_CheckState();
    414    if (result != NFCSTATUS_SUCCESS)
    415    {
    416       return result;
    417    }
    418 
    419    /* Parameters checking */
    420    if ((hRemoteDevice == 0) ||
    421        (pConfigInfo == NULL))
    422    {
    423       return NFCSTATUS_INVALID_PARAMETER;
    424    }
    425 
    426    /* Check device */
    427    result = static_CheckDevice(hRemoteDevice);
    428    if (result != NFCSTATUS_SUCCESS)
    429    {
    430       return result;
    431    }
    432 
    433    /* Get local infos */
    434    result = phFriNfc_Llcp_GetRemoteInfo(&gpphLibContext->llcp_cntx.sLlcpContext, pConfigInfo);
    435 
    436    return PHNFCSTATUS(result);
    437 }
    438 
    439 NFCSTATUS phLibNfc_Llcp_Socket( phLibNfc_Handle                  hRemoteDevice,
    440                                 phLibNfc_Llcp_eSocketType_t      eType,
    441                                 phLibNfc_Llcp_sSocketOptions_t*  psOptions,
    442                                 phNfc_sData_t*                   psWorkingBuffer,
    443                                 phLibNfc_Handle*                 phSocket,
    444                                 pphLibNfc_LlcpSocketErrCb_t      pErr_Cb,
    445                                 void*                            pContext
    446                                 )
    447 {
    448    NFCSTATUS                        result;
    449    phFriNfc_LlcpTransport_Socket_t  *psSocket;
    450 
    451    /* State checking */
    452    result = static_CheckState();
    453    if (result != NFCSTATUS_SUCCESS)
    454    {
    455       return result;
    456    }
    457 
    458    /* Parameters checking */
    459    /* NOTE: Transport Layer test psOption and psWorkingBuffer value */
    460    if ((hRemoteDevice == 0)      ||
    461        (phSocket == NULL)        ||
    462        (pErr_Cb == NULL))
    463    {
    464       return NFCSTATUS_INVALID_PARAMETER;
    465    }
    466 
    467    /* Check device */
    468    result = static_CheckDevice(hRemoteDevice);
    469    if (result != NFCSTATUS_SUCCESS)
    470    {
    471       return result;
    472    }
    473 
    474    /* Get local infos */
    475    result = phFriNfc_LlcpTransport_Socket(&gpphLibContext->llcp_cntx.sLlcpTransportContext,
    476                                           eType,
    477                                           psOptions,
    478                                           psWorkingBuffer,
    479                                           &psSocket,
    480                                           pErr_Cb,
    481                                           pContext);
    482 
    483    /* Send back the socket handle */
    484    *phSocket = (phLibNfc_Handle)psSocket;
    485 
    486    return PHNFCSTATUS(result);
    487 }
    488 
    489 NFCSTATUS phLibNfc_Llcp_Close( phLibNfc_Handle hSocket )
    490 {
    491    NFCSTATUS                        result;
    492    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    493 
    494    /* State checking */
    495    result = static_CheckState();
    496    if (result != NFCSTATUS_SUCCESS)
    497    {
    498       return result;
    499    }
    500 
    501    /* Parameters checking */
    502    if (hSocket == 0)
    503    {
    504       return NFCSTATUS_INVALID_PARAMETER;
    505    }
    506 
    507    /* Get local infos */
    508    result = phFriNfc_LlcpTransport_Close(psSocket);
    509 
    510    return PHNFCSTATUS(result);
    511 }
    512 
    513 NFCSTATUS phLibNfc_Llcp_SocketGetLocalOptions( phLibNfc_Handle                  hSocket,
    514                                                phLibNfc_Llcp_sSocketOptions_t*  psLocalOptions
    515                                                )
    516 {
    517    NFCSTATUS                        result;
    518    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    519 
    520    /* State checking */
    521    result = static_CheckState();
    522    if (result != NFCSTATUS_SUCCESS)
    523    {
    524       return result;
    525    }
    526 
    527    /* Parameters checking */
    528    if ((hSocket == 0) ||
    529        (psLocalOptions == NULL))
    530    {
    531       return NFCSTATUS_INVALID_PARAMETER;
    532    }
    533 
    534    /* Get local options */
    535    result = phFriNfc_LlcpTransport_SocketGetLocalOptions(psSocket, psLocalOptions);
    536 
    537    return PHNFCSTATUS(result);
    538 }
    539 
    540 NFCSTATUS phLibNfc_Llcp_SocketGetRemoteOptions( phLibNfc_Handle                  hSocket,
    541                                                 phLibNfc_Llcp_sSocketOptions_t*  psRemoteOptions
    542                                                 )
    543 {
    544    NFCSTATUS                        result;
    545    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    546 
    547    /* State checking */
    548    result = static_CheckState();
    549    if (result != NFCSTATUS_SUCCESS)
    550    {
    551       return result;
    552    }
    553 
    554    /* Parameters checking */
    555    if ((hSocket == 0) ||
    556        (psRemoteOptions == NULL))
    557    {
    558       return NFCSTATUS_INVALID_PARAMETER;
    559    }
    560 
    561    /* Get remote infos */
    562    result = phFriNfc_LlcpTransport_SocketGetRemoteOptions(psSocket, psRemoteOptions);
    563 
    564    return PHNFCSTATUS(result);
    565 }
    566 
    567 NFCSTATUS phLibNfc_Llcp_Bind( phLibNfc_Handle hSocket,
    568                               uint8_t         nSap
    569                               )
    570 {
    571    NFCSTATUS                        result;
    572    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    573 
    574    /* State checking */
    575    result = static_CheckState();
    576    if (result != NFCSTATUS_SUCCESS)
    577    {
    578       return result;
    579    }
    580 
    581    /* Parameters checking */
    582    if (hSocket == 0)
    583    {
    584       return NFCSTATUS_INVALID_PARAMETER;
    585    }
    586 
    587    /* Bind the socket to the designated port */
    588    result = phFriNfc_LlcpTransport_Bind(psSocket, nSap);
    589 
    590    return PHNFCSTATUS(result);
    591 }
    592 
    593 NFCSTATUS phLibNfc_Llcp_Listen( phLibNfc_Handle                  hSocket,
    594                                 phNfc_sData_t                    *psServiceName,
    595                                 pphLibNfc_LlcpSocketListenCb_t   pListen_Cb,
    596                                 void*                            pContext
    597                                 )
    598 {
    599    NFCSTATUS                        result;
    600    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    601 
    602    /* State checking */
    603    result = static_CheckState();
    604    if (result != NFCSTATUS_SUCCESS)
    605    {
    606       return result;
    607    }
    608 
    609    /* Parameters checking */
    610    /* NOTE : psServiceName may be NULL, do not test it ! */
    611    if ((hSocket == 0) ||
    612        (pListen_Cb == NULL))
    613    {
    614       return NFCSTATUS_INVALID_PARAMETER;
    615    }
    616 
    617    /* Start listening for incoming connections */
    618    result = phFriNfc_LlcpTransport_Listen( psSocket,
    619                                            psServiceName,
    620                                            (pphFriNfc_LlcpTransportSocketListenCb_t)pListen_Cb,
    621                                            pContext );
    622 
    623    return PHNFCSTATUS(result);
    624 }
    625 
    626 NFCSTATUS phLibNfc_Llcp_Accept( phLibNfc_Handle                  hSocket,
    627                                 phLibNfc_Llcp_sSocketOptions_t*  psOptions,
    628                                 phNfc_sData_t*                   psWorkingBuffer,
    629                                 pphLibNfc_LlcpSocketErrCb_t      pErr_Cb,
    630                                 pphLibNfc_LlcpSocketAcceptCb_t   pAccept_RspCb,
    631                                 void*                            pContext
    632                                 )
    633 {
    634    NFCSTATUS                        result;
    635    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    636 
    637    /* State checking */
    638    result = static_CheckState();
    639    if (result != NFCSTATUS_SUCCESS)
    640    {
    641       return result;
    642    }
    643 
    644    /* Parameters checking */
    645    if ((hSocket == 0)            ||
    646        (psOptions == NULL)       ||
    647        (psWorkingBuffer == NULL) ||
    648        (pErr_Cb == NULL)         ||
    649        (pAccept_RspCb == NULL))
    650    {
    651       return NFCSTATUS_INVALID_PARAMETER;
    652    }
    653 
    654    /* Accept incoming connection */
    655    result = phFriNfc_LlcpTransport_Accept( psSocket,
    656                                            psOptions,
    657                                            psWorkingBuffer,
    658                                            pErr_Cb,
    659                                            pAccept_RspCb,
    660                                            pContext );
    661 
    662    return PHNFCSTATUS(result);
    663 }
    664 
    665 NFCSTATUS phLibNfc_Llcp_Reject( phLibNfc_Handle                  hSocket,
    666                                 pphLibNfc_LlcpSocketRejectCb_t   pReject_RspCb,
    667                                 void*                            pContext
    668                                 )
    669 {
    670    NFCSTATUS                        result;
    671    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    672 
    673    /* State checking */
    674    result = static_CheckState();
    675    if (result != NFCSTATUS_SUCCESS)
    676    {
    677       return result;
    678    }
    679 
    680    /* Parameters checking */
    681    if ((hSocket == 0)            ||
    682        (pReject_RspCb == NULL))
    683    {
    684       return NFCSTATUS_INVALID_PARAMETER;
    685    }
    686 
    687    /* Reject incoming connection */
    688    result = phFriNfc_LlcpTransport_Reject( psSocket,
    689                                            pReject_RspCb,
    690                                            pContext );
    691 
    692    return PHNFCSTATUS(result);
    693 }
    694 
    695 NFCSTATUS phLibNfc_Llcp_Connect( phLibNfc_Handle                 hSocket,
    696                                  uint8_t                         nSap,
    697                                  pphLibNfc_LlcpSocketConnectCb_t pConnect_RspCb,
    698                                  void*                           pContext
    699                                  )
    700 {
    701    NFCSTATUS                        result;
    702    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    703 
    704    /* State checking */
    705    result = static_CheckState();
    706    if (result != NFCSTATUS_SUCCESS)
    707    {
    708       return result;
    709    }
    710 
    711    /* Parameters checking */
    712    if ((hSocket == 0)            ||
    713        (pConnect_RspCb == NULL))
    714    {
    715       return NFCSTATUS_INVALID_PARAMETER;
    716    }
    717 
    718    /* Try to connect on a remote service, given its SAP */
    719    result = phFriNfc_LlcpTransport_Connect( psSocket,
    720                                             nSap,
    721                                             pConnect_RspCb,
    722                                             pContext );
    723 
    724    return PHNFCSTATUS(result);
    725 }
    726 
    727 NFCSTATUS phLibNfc_Llcp_ConnectByUri( phLibNfc_Handle                 hSocket,
    728                                       phNfc_sData_t*                  psUri,
    729                                       pphLibNfc_LlcpSocketConnectCb_t pConnect_RspCb,
    730                                       void*                           pContext
    731                                       )
    732 {
    733    NFCSTATUS                        result;
    734    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    735 
    736    /* State checking */
    737    result = static_CheckState();
    738    if (result != NFCSTATUS_SUCCESS)
    739    {
    740       return result;
    741    }
    742 
    743    /* Parameters checking */
    744    if ((hSocket == 0)            ||
    745        (psUri   == NULL)         ||
    746        (pConnect_RspCb == NULL))
    747    {
    748       return NFCSTATUS_INVALID_PARAMETER;
    749    }
    750 
    751    /* Try to connect on a remote service, using SDP */
    752    result = phFriNfc_LlcpTransport_ConnectByUri( psSocket,
    753                                                  psUri,
    754                                                  pConnect_RspCb,
    755                                                  pContext );
    756 
    757    return PHNFCSTATUS(result);
    758 }
    759 
    760 NFCSTATUS phLibNfc_Llcp_Disconnect( phLibNfc_Handle                    hSocket,
    761                                     pphLibNfc_LlcpSocketDisconnectCb_t pDisconnect_RspCb,
    762                                     void*                              pContext
    763                                     )
    764 {
    765    NFCSTATUS                        result;
    766    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    767 
    768    /* State checking */
    769    result = static_CheckState();
    770    if (result != NFCSTATUS_SUCCESS)
    771    {
    772       return result;
    773    }
    774 
    775    /* Parameters checking */
    776    if ((hSocket == 0) ||
    777        (pDisconnect_RspCb == NULL))
    778    {
    779       return NFCSTATUS_INVALID_PARAMETER;
    780    }
    781 
    782    /* Disconnect a logical link */
    783    result = phFriNfc_LlcpTransport_Disconnect( psSocket,
    784                                                pDisconnect_RspCb,
    785                                                pContext );
    786 
    787    return PHNFCSTATUS(result);
    788 }
    789 
    790 NFCSTATUS phLibNfc_Llcp_Recv( phLibNfc_Handle              hSocket,
    791                               phNfc_sData_t*               psBuffer,
    792                               pphLibNfc_LlcpSocketRecvCb_t pRecv_RspCb,
    793                               void*                        pContext
    794                               )
    795 {
    796    NFCSTATUS                        result;
    797    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    798 
    799    /* State checking */
    800    result = static_CheckState();
    801    if (result != NFCSTATUS_SUCCESS)
    802    {
    803       return result;
    804    }
    805 
    806    /* Parameters checking */
    807    if ((hSocket == 0)     ||
    808        (psBuffer == NULL) ||
    809        (pRecv_RspCb == NULL))
    810    {
    811       return NFCSTATUS_INVALID_PARAMETER;
    812    }
    813 
    814    /* Receive data from the logical link */
    815    result = phFriNfc_LlcpTransport_Recv( psSocket,
    816                                          psBuffer,
    817                                          pRecv_RspCb,
    818                                          pContext );
    819 
    820    return PHNFCSTATUS(result);
    821 }
    822 
    823 NFCSTATUS phLibNfc_Llcp_RecvFrom( phLibNfc_Handle                   hSocket,
    824                                   phNfc_sData_t*                    psBuffer,
    825                                   pphLibNfc_LlcpSocketRecvFromCb_t  pRecv_Cb,
    826                                   void*                             pContext
    827                                   )
    828 {
    829    NFCSTATUS                        result;
    830    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    831 
    832    /* State checking */
    833    result = static_CheckState();
    834    if (result != NFCSTATUS_SUCCESS)
    835    {
    836       return result;
    837    }
    838 
    839    /* Parameters checking */
    840    if ((hSocket == 0)     ||
    841        (psBuffer == NULL) ||
    842        (pRecv_Cb == NULL))
    843    {
    844       return NFCSTATUS_INVALID_PARAMETER;
    845    }
    846 
    847    /* Receive data from the logical link */
    848    result = phFriNfc_LlcpTransport_RecvFrom( psSocket,
    849                                              psBuffer,
    850                                              pRecv_Cb,
    851                                              pContext );
    852 
    853    return PHNFCSTATUS(result);
    854 }
    855 
    856 NFCSTATUS phLibNfc_Llcp_Send( phLibNfc_Handle              hSocket,
    857                               phNfc_sData_t*               psBuffer,
    858                               pphLibNfc_LlcpSocketSendCb_t pSend_RspCb,
    859                               void*                        pContext
    860                               )
    861 {
    862    NFCSTATUS                        result;
    863    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    864 
    865    /* State checking */
    866    result = static_CheckState();
    867    if (result != NFCSTATUS_SUCCESS)
    868    {
    869       return result;
    870    }
    871 
    872    /* Parameters checking */
    873    if ((hSocket == 0)     ||
    874        (psBuffer == NULL) ||
    875        (pSend_RspCb == NULL))
    876    {
    877       return NFCSTATUS_INVALID_PARAMETER;
    878    }
    879 
    880    /* Send data to the logical link */
    881    result = phFriNfc_LlcpTransport_Send( psSocket,
    882                                          psBuffer,
    883                                          pSend_RspCb,
    884                                          pContext );
    885 
    886    return PHNFCSTATUS(result);
    887 }
    888 
    889 NFCSTATUS phLibNfc_Llcp_SendTo( phLibNfc_Handle               hSocket,
    890                                 uint8_t                       nSap,
    891                                 phNfc_sData_t*                psBuffer,
    892                                 pphLibNfc_LlcpSocketSendCb_t  pSend_RspCb,
    893                                 void*                         pContext
    894                                 )
    895 {
    896    NFCSTATUS                        result;
    897    phFriNfc_LlcpTransport_Socket_t  *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket;
    898 
    899    /* State checking */
    900    result = static_CheckState();
    901    if (result != NFCSTATUS_SUCCESS)
    902    {
    903       return result;
    904    }
    905 
    906    /* Parameters checking */
    907    if ((hSocket == 0)     ||
    908        (psBuffer == NULL) ||
    909        (pSend_RspCb == NULL))
    910    {
    911       return NFCSTATUS_INVALID_PARAMETER;
    912    }
    913 
    914    /* Send data to the logical link */
    915    result = phFriNfc_LlcpTransport_SendTo( psSocket,
    916                                            nSap,
    917                                            psBuffer,
    918                                            pSend_RspCb,
    919                                            pContext );
    920 
    921    return PHNFCSTATUS(result);
    922 }
    923