15d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
25d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Copyright (C) 2010 NXP Semiconductors
35d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
45d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Licensed under the Apache License, Version 2.0 (the "License");
55d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * you may not use this file except in compliance with the License.
65d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * You may obtain a copy of the License at
75d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
85d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *      http://www.apache.org/licenses/LICENSE-2.0
95d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Unless required by applicable law or agreed to in writing, software
115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * distributed under the License is distributed on an "AS IS" BASIS,
125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * See the License for the specific language governing permissions and
145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * limitations under the License.
155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \file  phLlcNfc_Frame.c
195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief To append the I or S or U frames (LLC header).
205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Project: NFC-FRI-1.1
225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Date: Tue Jun  1 14:41:26 2010 $
245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Author: ing02260 $
255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Revision: 1.88 $
265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Aliases: NFC_FRI1.1_WK1023_R35_1 $
275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*************************** Includes *******************************/
315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcTypes.h>
325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcStatus.h>
335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h>
345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc_Timer.h>
355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcInterface.h>
365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLlcNfc_DataTypes.h>
375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLlcNfc_Frame.h>
385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLlcNfc_Interface.h>
395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLlcNfc_Timer.h>
405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ANDROID
415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <string.h>
425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*********************** End of includes ****************************/
455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/***************************** Macros *******************************/
475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/************************ End of macros *****************************/
495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/***************************** Global variables *******************************/
515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_RELEASE_FLAG
535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    extern uint8_t             g_release_flag;
545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_RELEASE_FLAG */
555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/************************ End of global variables *****************************/
565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*********************** Local functions ****************************/
585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_UpdateCrc(
615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     crcByte,
625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint16_t    *pCrc
635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly);
645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions <b>process the received U frame</b> function
695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg This function is to process the U frame received from
715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*       the device
725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psLlcCtxt          Llc main structure information
745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] llcPacket          LLC packet information, inlcuding length information
755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                Operation successful.
775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ProcessUFrame (
835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt
845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly);
855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions <b>process the received S frame</b> function
905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg This function is to process the S frame received from
925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*       the device
935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psLlcCtxt          Llc main structure information
955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                Operation successful.
975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ProcessSFrame (
1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt
1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly);
1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions <b>Update I frame list</b> function
1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg This function checks the nr value with the stored I frames
1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*   and deletes the nodes which has been acknowledged.
1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in/out] psFrameInfo    Frame structure information
1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in/out] psListInfo     List information
1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval number of deleted frames
1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint8_t
1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_UpdateIFrameList(
1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t        *psFrameInfo,
1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *psListInfo
1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly);
1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions \b Delete list function
1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg Delete the front node from the list
1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psFrameInfo    Frame structure information
1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                Operation successful.
1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_DeleteIFrame (
1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                             phLlcNfc_StoreIFrame_t      *psList
1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                             );
1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions <b>Get the LLC header</b> function
1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg This function checks for the correctness fo the llc header
1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] llcHeader      The byte which gives the header information
1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval phLlcNfc_eU_frame      U frame type.
1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval phLlcNfc_eI_frame      I frame type.
1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval phLlcNfc_eS_frame      S frame type.
1585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval phLlcNfc_eErr_frame    Error type
1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_FrameType_t
1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ChkGetLlcFrameType (
1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                               uint8_t     llcHeader
1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                               );
1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions \b Peek the data function
1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg Get the packet information from the front node from the list
1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psListInfo The List information
1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] packetinfo The packet information from the front node of the list
1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                Operation successful.
1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_IFrameList_Peek (
1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           phLlcNfc_StoreIFrame_t      *psList,
1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           phLlcNfc_LlcPacket_t        **psPacketinfo,
1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           uint8_t                     position
1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           );
1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions <b>Update U frame information</b> function
1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg This function updates the U frame information in the
1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*       phLlcNfc_sFrame_t structure
1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in/out] psFrameInfo        Frame information structure
1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]     llcPayload         Llc payload information
1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                Operation successful.
2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_Update_ReceivedRSETInfo (
2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            phLlcNfc_Frame_t    *psFrameInfo,
2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            phLlcNfc_Payload_t  llcInfo
2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            );
2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC Reset frame information function
2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg resets ns and nr value, when ack for U frame is received
2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in, out] psLlcCtxt     Llc main structure information
2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                Operation successful.
2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
2225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ResetFrameInfo (
2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      phLlcNfc_Context_t  *psLlcCtxt
2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      );
2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC Reset frame sending function
2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg Send URSET frame to PN544
2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in, out] psLlcCtxt     Llc main structure information
2385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                 Operation successful.
2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_BUSY                    Write is pended, so wait till it completes.
2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_SendRSETFrame (
2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      phLlcNfc_Context_t  *psLlcCtxt
2475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      );
2485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_hal_nfc_llc_helper
2515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief LLC helper functions <b>process the received I frame</b> function
2535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \copydoc page_reg This function is to process the I frame received from
2555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*       the device
2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psLlcCtxt          Llc main structure information
2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                Operation successful.
2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ProcessIFrame (
2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt
2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly);
2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/******************** End of Local functions ************************/
2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/********************** Global variables ****************************/
2715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/******************** End of Global Variables ***********************/
2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phLlcNfc_H_Frame_Init (
2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t  *psLlcCtxt
2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (NULL != psLlcCtxt)
2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Set all the other values to 0 */
2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void)memset (&psLlcCtxt->s_frameinfo.s_llcpacket, 0,
2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sizeof(phLlcNfc_LlcPacket_t));
2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.window_size =
2865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PH_LLCNFC_U_FRAME_MAX_WIN_SIZE;
2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Initialise the window size, N(S) and N(R) */
2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef PIGGY_BACK
2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.s_recv_store.winsize_cnt = 0;
2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.s_send_store.winsize_cnt = 0;
2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.n_s = 0;
2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.n_r = 0;
2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.rejected_ns = DEFAULT_PACKET_INPUT;
2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_Frame_DeInit (
3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t    *psFrameInfo
3015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
3025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (NULL != psFrameInfo)
3045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Empty the frame information */
3065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void)memset(&psFrameInfo->s_llcpacket, 0,
3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            sizeof(phLlcNfc_LlcPacket_t));
3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_CreateUFramePayload (
3135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt,
3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t    *psLlcPacket,
3155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 *pLlcPacketLength,
3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcCmd_t       cmdType
3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*
3205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        U frame packet (RSET)
3215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 0 = Length (4 to 6 bytes)
3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 1 = Header
3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 2 = window size (2 >= window size <= 4)
3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 3 = capabilities (SREJ option enable/disable) (optional)
3255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 4 = Baud rate (optional)
3265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 5 = CRC1
3275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 6 = CRC2
3285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    */
3295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS           result = PHNFCSTVAL(CID_NFC_LLC,
3305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            NFCSTATUS_INVALID_PARAMETER);
3315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Buffer_t   *ps_llc_buf = NULL;
3325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t             index = 0;
3335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((NULL != psLlcCtxt) && (NULL != psLlcPacket)
3355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        && (NULL != pLlcPacketLength) &&
3365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ((phLlcNfc_e_rset == cmdType) || (phLlcNfc_e_ua == cmdType)))
3375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = NFCSTATUS_SUCCESS;
3395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf = &(psLlcPacket->s_llcbuf);
3405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Get the header information */
3415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf->sllcpayload.llcheader =
3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (uint8_t)PH_LLCNFC_U_HEADER_INIT;
3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (phLlcNfc_e_rset == cmdType)
3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* RSET command */
3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_llc_buf->sllcpayload.llcheader =
3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (uint8_t)SET_BITS8(
3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ps_llc_buf->sllcpayload.llcheader,
3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            PH_LLCNFC_U_FRAME_START_POS,
3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            PH_LLCNFC_U_FRAME_NO_OF_POS,
3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (uint8_t)phLlcNfc_e_rset);
3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Default window size */
3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_llc_buf->sllcpayload.llcpayload[index] =
3545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_LLCNFC_U_FRAME_MAX_WIN_SIZE;
3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            index++;
3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Endpoint capabilities, SREJ not supported */
3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_llc_buf->sllcpayload.llcpayload[index] =
3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_LLCNFC_SREJ_BYTE_VALUE;
3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            index++;
3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ENABLE_BAUDRATE
3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* baud rate 0x00 = 9600, 0x05 = 115200 */
3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_llc_buf->sllcpayload.llcpayload[index] =
3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (uint8_t)phLlcNfc_e_115200;
3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            index++;
3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef ENABLE_BAUDRATE */
3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* UA frame */
3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_llc_buf->sllcpayload.llcheader = (uint8_t)
3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                SET_BITS8(ps_llc_buf->sllcpayload.llcheader,
3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            PH_LLCNFC_U_FRAME_START_POS,
3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            PH_LLCNFC_U_FRAME_NO_OF_POS,
3755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (uint8_t)phLlcNfc_e_ua);
3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* LLC length byte updated (index + 2 CRC bytes +
3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        1 byte of header) */
3795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf->llc_length_byte = (index +
3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            PH_LLCNFC_NUM_OF_CRC_BYTES + 1);
3815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Total LLC buffer size */
3825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        *pLlcPacketLength = psLlcPacket->llcbuf_len =
3835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (ps_llc_buf->llc_length_byte + 1);
3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*
3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcPacket->s_llcbuf :
3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                consists llc length byte + llc header + data + CRC
3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (which needs to be calculated by the below function)
3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcPacket->llcbuf_len :
3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Total length of the above buffer
3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcPacket->llcbuf_len - 2 :
3915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                -2 because the CRC has to be calculated, only for the
3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                bytes which has llc length byte + llc header + data.
3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                But total length (llcbuf_len) consists of above mentioned
3945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                things with 2 byte CRC
3955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcPacket->s_llcbuf.sllcpayload.llcpayload :
3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                consists only data (no length byte and no llc header)
3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (psLlcPacket->llcbuf_len - 4) :
3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                is the array index of the first CRC byte to be calculated
3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (psLlcPacket->llcbuf_len - 3) :
4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                is the array index of the second CRC byte to be calculated
4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        */
4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        index = psLlcPacket->llcbuf_len;
4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLlcNfc_H_ComputeCrc((uint8_t *)ps_llc_buf,
4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (psLlcPacket->llcbuf_len - 2),
4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                &(ps_llc_buf->sllcpayload.llcpayload[(index - 4)]),
4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                &(ps_llc_buf->sllcpayload.llcpayload[(index - 3)]));
4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_CreateSFramePayload (
4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t    *psFrameInfo,
416b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    phLlcNfc_LlcPacket_t    *psLlcPacket,
4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcCmd_t   cmdType
4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*
4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        S frame packet (RR or RNR or REJ or SREJ). Total bytes = 4
4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 0 = Length (Length = 3 always for S frame)
4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 1 = Header
4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 2 = CRC1
4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Byte 3 = CRC2
4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    */
4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               result = NFCSTATUS_SUCCESS;
4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Buffer_t       *ps_llc_buf = NULL;
4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 length = 0;
4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
431b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    ps_llc_buf = &(psLlcPacket->s_llcbuf);
4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Initial S frame header */
4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_llc_buf->sllcpayload.llcheader = PH_LLCNFC_S_HEADER_INIT;
4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Update the N(R) value */
4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_llc_buf->sllcpayload.llcheader = (uint8_t)SET_BITS8(
4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                ps_llc_buf->sllcpayload.llcheader,
4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_LLCNFC_NR_START_BIT_POS,
4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_LLCNFC_NR_NS_NO_OF_BITS,
4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psFrameInfo->n_r);
4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Update the type bits of S frame */
4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_llc_buf->sllcpayload.llcheader = (uint8_t)
4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (ps_llc_buf->sllcpayload.llcheader | (uint8_t)cmdType);
4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Maximum S frame length */
447b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    psLlcPacket->llcbuf_len = (uint8_t)PH_LLCNFC_MAX_S_FRAME_LEN;
4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* S frame length byte value */
4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_llc_buf->llc_length_byte = (uint8_t)
450b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (psLlcPacket->llcbuf_len - 1);
4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*
4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psFrameInfo->s_llcpacket.s_llcbuf :
4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                consists llc length byte + llc header + data + CRC
4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (which needs to be calculated by the below function)
4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psFrameInfo->s_llcpacket.llcbuf_len :
4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Total length of the above buffer
4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psFrameInfo->s_llcpacket.llcbuf_len - 2 :
4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                -2 because the CRC has to be calculated, only for the
4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                bytes which has llc length byte + llc header + data.
4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                But total length (llcbuf_len) consists of above mentioned
4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                things with 2 byte CRC
4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psFrameInfo->s_llcpacket.s_llcbuf.sllcpayload.llcpayload :
4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                consists only data (no length byte and no llc header)
4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psFrameInfo->s_llcpacket.s_llcbuf.sllcpayload.llcpayload :
4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                contains only data sent by user.
4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (psFrameInfo->s_llcpacket.llcbuf_len - 4) :
4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                is the array index of the first CRC byte to be calculated
4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (psFrameInfo->s_llcpacket.llcbuf_len - 3) :
4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                is the array index of the second CRC byte to be calculated
4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    */
472b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    length = psLlcPacket->llcbuf_len;
4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_H_ComputeCrc(
4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (uint8_t *)ps_llc_buf, (length - 2),
4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        &(ps_llc_buf->sllcpayload.llcpayload[(length - 4)]),
4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        &(ps_llc_buf->sllcpayload.llcpayload[(length - 3)]));
4775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_CreateIFramePayload (
4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t        *psFrameInfo,
4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t    *psLlcPacket,
4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 *pLlcBuf,
4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 llcBufLength
4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS           result = PHNFCSTVAL(CID_NFC_LLC,
4905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            NFCSTATUS_INVALID_PARAMETER);
4915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Buffer_t   *ps_llc_buf = NULL;
4925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((NULL != psFrameInfo) && (NULL != psLlcPacket) &&
4945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (NULL != pLlcBuf) && (llcBufLength > 0))
4955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = NFCSTATUS_SUCCESS;
4975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf = &(psLlcPacket->s_llcbuf);
4985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void)memcpy(&(ps_llc_buf->sllcpayload.llcpayload[0]),
5005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pLlcBuf, llcBufLength);
5015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcPacket->llcbuf_len = (uint8_t)llcBufLength;
5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* I frame header byte */
5055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf->sllcpayload.llcheader = PH_LLCNFC_I_HEADER_INIT;
5065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Set the N(S) value */
5085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf->sllcpayload.llcheader = (uint8_t)
5095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            SET_BITS8(
5105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_llc_buf->sllcpayload.llcheader,
5115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NS_START_BIT_POS,
5125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NR_NS_NO_OF_BITS,
5135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psFrameInfo->n_s);
5145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Set the N(R) value */
5165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf->sllcpayload.llcheader = (uint8_t)
5175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            SET_BITS8(
5185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_llc_buf->sllcpayload.llcheader,
5195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NR_START_BIT_POS,
5205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NR_NS_NO_OF_BITS,
5215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psFrameInfo->n_r);
5225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Update the length byte, llc length byte value includes
5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            data + CRC bytes + llc length byte */
5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_llc_buf->llc_length_byte =
5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (psLlcPacket->llcbuf_len +
5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_NUM_OF_CRC_BYTES + 1);
5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Update total length, Total length is always equal to
5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            llc length byte + 1 */
5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcPacket->llcbuf_len =
5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (ps_llc_buf->llc_length_byte + 1);
5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*
5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psFrameInfo->s_llcpacket.s_llcbuf :
5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    consists llc length byte + llc header + data + CRC (which
5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    needs to be calculated by the below function)
5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psFrameInfo->s_llcpacket.llcbuf_len :
5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Total length of the above buffer
5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psFrameInfo->s_llcpacket.llcbuf_len - 2 :
5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    -2 because the CRC has to be calculated, only for the
5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    bytes which has llc length byte + llc header + data.
5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    But total length (llcbuf_len) consists of above mentioned
5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    things with 2 byte CRC
5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psFrameInfo->s_llcpacket.s_llcbuf.sllcpayload.llcpayload :
5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    contains only data sent by user.
5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (psFrameInfo->s_llcpacket.llcbuf_len - 4) :
5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    is the array index of the first CRC byte to be calculated
5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (psFrameInfo->s_llcpacket.llcbuf_len - 3) :
5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    is the array index of the second CRC byte to be calculated
5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        */
5535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLlcNfc_H_ComputeCrc(
5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (uint8_t*)ps_llc_buf,
5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (psLlcPacket->llcbuf_len - 2),
5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            &(ps_llc_buf->sllcpayload.llcpayload
5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        [(psLlcPacket->llcbuf_len - 4)]),
5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            &(ps_llc_buf->sllcpayload.llcpayload
5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        [(psLlcPacket->llcbuf_len - 3)]));
5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
5635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_FrameType_t
5695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ChkGetLlcFrameType (
5705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t llcHeader
5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_FrameType_t    frame_type = phLlcNfc_eErr_frame;
5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Mask the header byte to know the actual frame types */
5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    switch((llcHeader & PH_LLCNFC_LLC_HEADER_MASK))
5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case PH_LLCNFC_U_HEADER_INIT:
5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            frame_type = phLlcNfc_eU_frame;
5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case PH_LLCNFC_S_HEADER_INIT:
5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            frame_type = phLlcNfc_eS_frame;
5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        default:
5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (PH_LLCNFC_I_HEADER_INIT ==
5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (PH_LLCNFC_I_FRM_HEADER_MASK & llcHeader))
5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                frame_type = phLlcNfc_eI_frame;
5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                frame_type = phLlcNfc_eErr_frame;
6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return frame_type;
6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_Update_ReceivedRSETInfo (
6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t    *psFrameInfo,
6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Payload_t  llcInfo
6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_FORMAT);
6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     payload_index = 0;
6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((llcInfo.llcpayload[payload_index] >= PH_LLCNFC_U_FRAME_MIN_WIN_SIZE) &&
6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (llcInfo.llcpayload[payload_index] <= PH_LLCNFC_U_FRAME_MAX_WIN_SIZE))
6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = NFCSTATUS_SUCCESS;
6215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* From the received buffer, get the window size from the
6225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            3rd byte (recvUBufLen[3]) of the buffer */
6235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psFrameInfo->window_size = llcInfo.llcpayload[payload_index];
6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        payload_index = (uint8_t)(payload_index + 1);
6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* If 4th byte of the receive buffer (pRecvUBuf[4]) is
6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            0x01 then SREJ can come from the device*/
6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psFrameInfo->srej_on_off = ((PH_LLCNFC_SREJ_BYTE_VALUE ==
6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        llcInfo.llcpayload[payload_index])?
6305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_SREJ_BYTE_VALUE:0);
6315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* For present implementation, this should be always false
6335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        later stage remove if statement to work */
6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (PH_LLCNFC_SREJ_BYTE_VALUE != psFrameInfo->srej_on_off)
6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_FORMAT);
6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            payload_index = (uint8_t)(payload_index + 1);
6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (llcInfo.llcpayload[payload_index] >
6445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (uint8_t)phLlcNfc_e_1228000)
6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Error byte */
6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_FORMAT);
6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Get the baud rate from the 5th byte of the receive buffer */
6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                psFrameInfo->baud_rate = (phLlcNfc_LlcBaudRate_t)
6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (llcInfo.llcpayload[payload_index]);
6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
6595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
6605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
6625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyuint8_t
6635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_UpdateIFrameList(
6645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t        *psFrameInfo,
6655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *psListInfo
6665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
6675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
6685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               result = NFCSTATUS_SUCCESS;
6695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t    *pspktInfo = NULL;
6705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 while_exit = FALSE;
6715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 nr = 0;
6725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 ns = 0;
6735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 no_of_del_frames = 0;
6745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PHNFC_UNUSED_VARIABLE(result);
6765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(0 == psListInfo->winsize_cnt)
6775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        while_exit = TRUE;
6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    while (FALSE == while_exit)
6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Get the first node from the list */
6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = phLlcNfc_H_IFrameList_Peek (psListInfo, &pspktInfo,
6845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            DEFAULT_PACKET_INPUT);
6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != pspktInfo)
6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Get the N(R) value of the received packet and N(S) value of the
6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                sent stored i frame */
6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ns = (uint8_t)GET_BITS8 (
6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    pspktInfo->s_llcbuf.sllcpayload.llcheader,
6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NS_START_BIT_POS,
6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NR_NS_NO_OF_BITS);
6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            nr = (uint8_t)GET_BITS8(
6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psFrameInfo->s_recvpacket.s_llcbuf.sllcpayload.llcheader,
6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NR_START_BIT_POS,
6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_NR_NS_NO_OF_BITS);
6985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Check the value of each i frame N(S) and
7005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                received ACKs N(R) */
7015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(((ns <= nr) && ((nr - ns) <= psFrameInfo->window_size))
7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                || ((ns > nr) && (((PH_LLCNFC_MOD_NS_NR + nr) - ns) <=
7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_U_FRAME_MAX_WIN_SIZE)))
7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
7065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(((ns < nr) && ((nr - ns) <= psFrameInfo->window_size))
7075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                || ((ns > nr) && (((PH_LLCNFC_MOD_NS_NR + nr) - ns) <=
7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_U_FRAME_MAX_WIN_SIZE)))
7095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phLlcNfc_H_DeleteIFrame (psListInfo);
7115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                no_of_del_frames = (uint8_t)(no_of_del_frames + 1);
7125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
7145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                while_exit = TRUE;
7165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(0 == psListInfo->winsize_cnt)
7195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                while_exit = TRUE;
7215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
7245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            while_exit = TRUE;
7265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return no_of_del_frames;
7295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
7325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_SendUserIFrame (
7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt,
7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *psListInfo
7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               result = NFCSTATUS_SUCCESS;
7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t        *ps_frame_info = NULL;
739b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    phLlcNfc_LlcPacket_t    s_create_packet;
7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t    *ps_get_packet = NULL;
7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Payload_t      *ps_llc_payload = NULL;
7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *ps_store_frame = NULL;
7435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 llc_header = 0,
7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            length = 0;
7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((NULL == psLlcCtxt) || (NULL == psListInfo))
7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = PHNFCSTVAL (CID_NFC_LLC, NFCSTATUS_INVALID_PARAMETER);
7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if (0 == psListInfo->winsize_cnt)
7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = PHNFCSTVAL (CID_NFC_LLC, NFCSTATUS_NOT_ALLOWED);
7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_frame_info = &(psLlcCtxt->s_frameinfo);
7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_store_frame = &(ps_frame_info->s_send_store);
7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (
7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (ps_frame_info->n_s != ((ps_store_frame->winsize_cnt +
7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_store_frame->start_pos) % PH_LLCNFC_MOD_NS_NR))
7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            )
7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Get the stored I frame, only if the new frame is sent
7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                from the upper layer */
766b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet,
7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                ps_frame_info->n_s);
7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != ps_get_packet)
7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            llc_header = ps_get_packet->s_llcbuf.sllcpayload.llcheader;
7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Update n(r) value for the header */
7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            llc_header = (uint8_t)(llc_header | ps_frame_info->n_r);
7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Create the packet */
778b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            (void)memcpy ((void *)&(s_create_packet), (void *)ps_get_packet,
7795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof (phLlcNfc_LlcPacket_t));
7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
781b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            s_create_packet.s_llcbuf.sllcpayload.llcheader = llc_header;
782b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            ps_llc_payload = &(s_create_packet.s_llcbuf.sllcpayload);
7835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Length of the complete llc buffer, sent to PN544 */
785b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            length = s_create_packet.llcbuf_len;
7865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Compute CRC for the created packet */
788b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            phLlcNfc_H_ComputeCrc ((uint8_t *)&(s_create_packet.s_llcbuf),
7895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (length - 2),
7905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (uint8_t *)&(ps_llc_payload->llcpayload[(length - 4)]),
7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (uint8_t *)&(ps_llc_payload->llcpayload[(length - 3)]));
7925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Send the i frame */
794b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            result = phLlcNfc_Interface_Write (psLlcCtxt,
795b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint8_t *)&(s_create_packet.s_llcbuf),
796b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint32_t)s_create_packet.llcbuf_len);
7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_status = result;
7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NFCSTATUS_BUSY == PHNFCSTATUS (result))
8015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* The below check is added because, write is already pended by some other
8035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    operation, so it has to complete, when it completes, then immediately
8045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    next write shall be called using the below updated variable
8055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    The below variable is checked for the resend or rejected i frame
8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    because if due to timer or reject frame from PN544, an I frame
8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    has been sent (means write has been pended then the variable shall
8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    not be overwritten.
8105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                */
8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_wait_call = (phLlcNfc_eSentFrameType_t)
8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (((resend_i_frame == ps_frame_info->write_wait_call) ||
8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (rejected_i_frame == ps_frame_info->write_wait_call)) ?
8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ps_frame_info->write_wait_call : user_i_frame);
8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (NFCSTATUS_PENDING == result)
8195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
8205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Start the timer */
8215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)phLlcNfc_StartTimers (PH_LLCNFC_GUARDTIMER,
8225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                ps_frame_info->n_s);
8235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* "sent_frame_type is updated" only if the data is
8255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        written to the lower layer */
8265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->sent_frame_type = user_i_frame;
8275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
8285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
8325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
8335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_SendRejectedIFrame (
8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt,
8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *psListInfo,
8385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 ns_rejected
8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               result = NFCSTATUS_SUCCESS;
8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t        *ps_frame_info = NULL;
843b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    phLlcNfc_LlcPacket_t    s_create_packet;
8445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t    *ps_get_packet = NULL;
8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Payload_t      *ps_llc_payload = NULL;
8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *ps_store_frame = NULL;
8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 llc_header = 0;
8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 length = 0;
8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((NULL == psLlcCtxt) || (NULL == psListInfo))
8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = PHNFCSTVAL (CID_NFC_LLC, NFCSTATUS_INVALID_PARAMETER);
8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if (0 == psListInfo->winsize_cnt)
8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = PHNFCSTVAL (CID_NFC_LLC, NFCSTATUS_NOT_ALLOWED);
8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_frame_info = &(psLlcCtxt->s_frameinfo);
8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_store_frame = &(ps_frame_info->s_send_store);
8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (ns_rejected < (uint8_t)(ps_store_frame->winsize_cnt +
8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_store_frame->start_pos))
8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* To send rejected frame, first thing shall be done is
8685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                windows size count shall be checked. if the
8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                start position
8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                */
8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (invalid_frame !=
8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_store_frame->s_llcpacket[ns_rejected].frame_to_send)
8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Above check is added to know only if   */
875b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet,
8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    ns_rejected);
8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->rejected_ns = DEFAULT_PACKET_INPUT;
8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Get the stored I frame, only if the new frame is sent
8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    from the upper layer */
8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_H_SendUserIFrame (psLlcCtxt, psListInfo);
8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != ps_get_packet)
8885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            llc_header = ps_get_packet->s_llcbuf.sllcpayload.llcheader;
8905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Update n(r) value for the header */
8925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            llc_header = (uint8_t)(llc_header | ps_frame_info->n_r);
8935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Create the packet */
895b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            (void)memcpy ((void *)&(s_create_packet), (void *)ps_get_packet,
8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof (phLlcNfc_LlcPacket_t));
8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
898b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            s_create_packet.s_llcbuf.sllcpayload.llcheader = llc_header;
899b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            ps_llc_payload = &(s_create_packet.s_llcbuf.sllcpayload);
9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Length of the complete llc buffer, sent to PN544 */
902b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            length = s_create_packet.llcbuf_len;
9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Compute CRC for the created packet */
905b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            phLlcNfc_H_ComputeCrc ((uint8_t *)&(s_create_packet.s_llcbuf),
9065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (length - 2),
9075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (uint8_t *)&(ps_llc_payload->llcpayload[(length - 4)]),
9085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (uint8_t *)&(ps_llc_payload->llcpayload[(length - 3)]));
9095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Send the i frame */
9115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_Interface_Write (psLlcCtxt,
912b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint8_t *)&(s_create_packet.s_llcbuf),
913b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint32_t)s_create_packet.llcbuf_len);
9145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_status = result;
9165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NFCSTATUS_BUSY == PHNFCSTATUS (result))
9185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
9195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Already a frame is sent and response is waited for the sent frame,
9205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    so update the below variable */
9215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_wait_call = (phLlcNfc_eSentFrameType_t)
9225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (((ns_rejected != ps_store_frame->start_pos) &&
923b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                                (resend_i_frame != ps_frame_info->write_wait_call))?
9245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                rejected_i_frame : ps_frame_info->write_wait_call);
9255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
9265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
9275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
9285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* NFCSTATUS_PENDING means that the no other write is pending, apart
9295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    from the present write
9305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Start the timer */
9325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (void)phLlcNfc_StartTimers (PH_LLCNFC_GUARDTIMER, ns_rejected);
9335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* "sent_frame_type is updated" only if the data is
9355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    written to the lower layer. This will be used in the write
9365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    response callback and also indicates, what is the frame sent
9375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    and why
9385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 */
9395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->sent_frame_type = rejected_i_frame;
9405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if ((ns_rejected + 1) < ps_frame_info->n_s)
9425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
9435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->rejected_ns = (uint8_t)(ns_rejected + 1);
9445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->write_status = PHNFCSTVAL(CID_NFC_LLC,
9465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    NFCSTATUS_BUSY);
9475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if (invalid_frame ==
9495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_store_frame->s_llcpacket[ns_rejected].frame_to_send)
9505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
9515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_frame_info->rejected_ns = DEFAULT_PACKET_INPUT;
9525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_frame_info->write_wait_call = user_i_frame;
9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    else
9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_frame_info->write_wait_call = rejected_i_frame;
9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->rejected_ns = DEFAULT_PACKET_INPUT;
9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* This check is added to see that new frame has arrived
9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        from the upper layer */
9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if (ps_frame_info->n_s < (ps_store_frame->start_pos +
9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_store_frame->winsize_cnt))
9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_frame_info->write_wait_call = user_i_frame;
9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_SendTimedOutIFrame (
9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt,
9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *psListInfo,
9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 frame_to_send
9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               result = NFCSTATUS_SUCCESS;
9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t        *ps_frame_info = NULL;
9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Timerinfo_t    *ps_timer_info = NULL;
986b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    phLlcNfc_LlcPacket_t    s_create_packet;
9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t    *ps_get_packet = NULL;
9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Payload_t      *ps_llc_payload = NULL;
9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t  *ps_store_frame = NULL;
9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PHNFC_UNUSED_VARIABLE(frame_to_send);
9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((NULL == psLlcCtxt) || (NULL == psListInfo))
9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_PARAMETER);
9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if (psListInfo->winsize_cnt == 0)
9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_NOT_ALLOWED);
9995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
10005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
10015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
10025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uint8_t                 llc_header = 0;
10035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uint8_t                 length = 0;
10045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uint8_t                 timer_count = 0;
10055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uint8_t                 timer_index = 0;
10065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uint8_t                 ns_index = 0;
10075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_frame_info = &(psLlcCtxt->s_frameinfo);
10095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_timer_info = &(psLlcCtxt->s_timerinfo);
10105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_store_frame = &(ps_frame_info->s_send_store);
10115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        timer_index = ps_timer_info->index_to_send;
10135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        timer_count = ps_timer_info->guard_to_count;
10145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ns_index = ps_timer_info->timer_ns_value[timer_index];
10155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PH_LLCNFC_DEBUG("SEND TIMEOUT CALL WIN SIZE CNT : 0x%02X\n", ps_store_frame->winsize_cnt);
10175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PH_LLCNFC_DEBUG("SEND TIMEOUT CALL START POS : 0x%02X\n", ps_store_frame->start_pos);
10185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PH_LLCNFC_DEBUG("SEND TIMEOUT CALL N S value : 0x%02X\n", ps_frame_info->n_s);
1019b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        PH_LLCNFC_DEBUG("SEND TIMEOUT TIMER INDEX : 0x%02X\n", timer_index);
10205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PH_LLCNFC_DEBUG("SEND TIMEOUT CALL frame type : 0x%02X\n", ps_timer_info->frame_type[timer_index]);
10215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (resend_i_frame == ps_timer_info->frame_type[timer_index])
10235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
10245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Get the stored I frame */
1025b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet,
10265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                ns_index);
10275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
10285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
102934ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly        PH_LLCNFC_DEBUG("SEND TIMEOUT CALL Packet : 0x%p\n", ps_get_packet);
10305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != ps_get_packet)
10315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
10325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            llc_header = ps_get_packet->s_llcbuf.sllcpayload.llcheader;
10335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Update n(r) value for the header */
10355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            llc_header = (uint8_t)(llc_header | ps_frame_info->n_r);
10365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* create the packet */
1038b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            (void)memcpy ((void *)&(s_create_packet), (void *)ps_get_packet,
10395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof (phLlcNfc_LlcPacket_t));
10405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1041b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            s_create_packet.s_llcbuf.sllcpayload.llcheader = llc_header;
1042b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            ps_llc_payload = &(s_create_packet.s_llcbuf.sllcpayload);
10435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Length of the complete llc buffer, sent to PN544 */
1045b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            length = s_create_packet.llcbuf_len;
10465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Compute CRC */
1048b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            phLlcNfc_H_ComputeCrc((uint8_t *)&(s_create_packet.s_llcbuf),
10495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (length - 2),
1050b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                        (uint8_t *)&(ps_llc_payload->llcpayload[(length - 4)]),
10515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (uint8_t *)&(ps_llc_payload->llcpayload[(length - 3)]));
10525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Send the i frame */
10545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_Interface_Write (psLlcCtxt,
1055b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint8_t *)&(s_create_packet.s_llcbuf),
1056b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint32_t)s_create_packet.llcbuf_len);
10575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_status = result;
10595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PH_LLCNFC_DEBUG("SEND TIMEOUT CALL Write status : 0x%02X\n", result);
10605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NFCSTATUS_BUSY == PHNFCSTATUS (result))
10625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
10635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_wait_call = resend_i_frame;
10645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
10655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
10665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
10675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* result = NFCSTATUS_PENDING and
10685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Timer is not started because the remaining timer
10695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    will be running */
10705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                uint16_t                time_out_value = 0;
10715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Each frame has the send count, so increment this
10735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    as soon as the frame is sent */
10745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_timer_info->iframe_send_count[timer_index] = (uint8_t)
10755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (ps_timer_info->iframe_send_count[timer_index] + 1);
10765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_DEBUG("SEND TIMEOUT CALL timer index : 0x%02X\n", timer_index);
10785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (timer_index > 0)
10805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1081b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                    PH_LLCNFC_DEBUG("SEND TIMEOUT CALL GUARD TO VALUE : 0x%02X\n", ps_timer_info->guard_to_value[(timer_index - 1)]);
10825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Copy the maximum time-out value. */
10835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    time_out_value = (uint16_t)
10845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ((ps_timer_info->guard_to_value[(timer_index - 1)] >=
10855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_GUARD_TO_VALUE) ?
10865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (ps_timer_info->guard_to_value[(timer_index - 1)] +
10875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_RESOLUTION):
10885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_GUARD_TO_VALUE);
10895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
10905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
10915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
10925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* If the timer_index is 0 means, the previous timed out
10935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        frame is the last frame in the list */
10945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    time_out_value = (uint16_t)
10955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ((ps_timer_info->guard_to_value[(timer_count - 1)] >=
10965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_GUARD_TO_VALUE) ?
10975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (ps_timer_info->guard_to_value[(timer_count - 1)] +
10985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_RESOLUTION):
10995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_GUARD_TO_VALUE);
11005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
11015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_timer_info->guard_to_value[timer_index] = time_out_value;
11035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->sent_frame_type = resend_i_frame;
11055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_timer_info->frame_type[timer_index] = invalid_frame;
11075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_DEBUG("SEND TIMEOUT CALL Next frame type : 0x%02X\n", ps_timer_info->frame_type[((timer_index + 1) % PH_LLCNFC_MAX_ACK_GUARD_TIMER)]);
11095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Now check if next timer has expired, if yes,
11105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    set the index to next, on receiving the write response
11115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    callback for this send, then next frame can be sent */
11125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (resend_i_frame ==
11135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_timer_info->frame_type[((timer_index + 1) %
11145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_MAX_ACK_GUARD_TIMER)])
11155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
11165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* If next frame has to be sent, then update write wait */
11175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->write_status = NFCSTATUS_BUSY;
11185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->write_wait_call = resend_i_frame;
11195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_timer_info->index_to_send = (uint8_t)
11205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            ((timer_index + 1) %
11215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            PH_LLCNFC_MAX_ACK_GUARD_TIMER);
11225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
11235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
11245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
11255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Timer is not expired,
11265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Now, Check if the new frame is ready to be sent, if yes,
11275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        then update the variable */
11285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if (
11295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (ps_frame_info->n_s != ((ps_store_frame->winsize_cnt +
11305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_store_frame->start_pos) % PH_LLCNFC_MOD_NS_NR))
11315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        )
11325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
11335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_frame_info->write_status = PHNFCSTVAL (CID_NFC_LLC,
11345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    NFCSTATUS_BUSY);
11355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_frame_info->write_wait_call = user_i_frame;
11365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
11375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
11385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
11405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_StartTimers (PH_LLCNFC_GUARDTIMER,
11415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        ((llc_header >>
11425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        PH_LLCNFC_NS_START_BIT_POS) |
11435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        MAX_NS_NR_VALUE));
11445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if 0 */
11455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
11475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
11495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
11505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (
11515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (ps_frame_info->n_s != ((ps_store_frame->winsize_cnt +
11525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_store_frame->start_pos) % PH_LLCNFC_MOD_NS_NR))
11535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                )
11545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
11555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_status = PHNFCSTVAL (CID_NFC_LLC,
11565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            NFCSTATUS_BUSY);
11575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_wait_call = user_i_frame;
11585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
11595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
11615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
11635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
11645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
11675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ProcessIFrame (
11685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt
11695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
11705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
11715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
11725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     ns_index = 0;
11735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if defined (LLC_SEND_RR_ACK)
11745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* uint8_t                     nr_index = 0; */
11755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if defined (LLC_SEND_RR_ACK) */
11765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t            *ps_frame_info = NULL;
11775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t      *ps_store_frame = NULL;
11785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t        *ps_recv_pkt = NULL;
11795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcCmd_t           cmdtype = phLlcNfc_e_error;
11805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_eSentFrameType_t   eframe_type = invalid_frame;
11815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     dont_send_s_frame = FALSE;
11825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     no_of_del_frames = 0;
118334ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly    phNfc_sCompletionInfo_t     notifyinfo = {0,0,0};
11845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef RECV_NR_CHECK_ENABLE
11865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     recvd_nr = 0;
11875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef RECV_NR_CHECK_ENABLE */
11885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_frame_info = &(psLlcCtxt->s_frameinfo);
11905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_store_frame = &(ps_frame_info->s_send_store);
11915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_recv_pkt = &(ps_frame_info->s_recvpacket);
11925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PHNFC_UNUSED_VARIABLE(result);
11945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Received buffer, N(S) value */
11955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ns_index = (uint8_t)GET_BITS8(
11965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_recv_pkt->s_llcbuf.sllcpayload.llcheader,
11975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_NS_START_BIT_POS,
11985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_NR_NS_NO_OF_BITS);
11995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("NS START POS BEFORE DEL : 0x%02X\n", ps_store_frame->start_pos);
12015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("WIN SIZE BEFORE DEL : 0x%02X\n", ps_store_frame->winsize_cnt);
12025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Correct frame is received, so remove the stored i frame info */
12045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    no_of_del_frames = phLlcNfc_H_UpdateIFrameList (ps_frame_info,
12055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                &(ps_frame_info->s_send_store));
12065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("NS START POS AFTER DEL : 0x%02X\n", ps_store_frame->start_pos);
12085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("WIN SIZE AFTER DEL : 0x%02X\n", ps_store_frame->winsize_cnt);
12095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef RECV_NR_CHECK_ENABLE
12115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    recvd_nr = (uint8_t)GET_BITS8(
12135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_recv_pkt->s_llcbuf.sllcpayload.llcheader,
12145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_NR_START_BIT_POS,
12155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_NR_NS_NO_OF_BITS);
12165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (((ps_frame_info->n_s > recvd_nr) &&
12185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (0 == ((ps_frame_info->n_s + 1) % PH_LLCNFC_MOD_NS_NR)))
12195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (recvd_nr > ps_frame_info->n_s))
12205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else /* #ifdef RECV_NR_CHECK_ENABLE */
12225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (no_of_del_frames > 0)
12245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef RECV_NR_CHECK_ENABLE */
12265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLlcNfc_StopTimers (PH_LLCNFC_GUARDTIMER, no_of_del_frames);
12285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Received buffer, N(S) value = N(R) of host (our
12315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        structure) then send RR type of s frame else send
12325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        REJ type of s frame */
12335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((ns_index == ps_frame_info->n_r)
12345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if defined (LLC_SEND_RR_ACK)
12355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || ((ns_index < ps_frame_info->n_r) &&
12375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ((ps_frame_info->n_r - ns_index) < ps_frame_info->window_size))
12385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || ((ns_index > ps_frame_info->n_r) &&
12395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ((ns_index - ps_frame_info->n_r) > ps_frame_info->window_size))
12405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if defined (LLC_SEND_RR_ACK) */
12425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         )
12435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PH_LLCNFC_PRINT(" Type bits of S frame to be sent is RR \n");
12455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_frame_info->recv_error_count = 0;
12465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_frame_info->send_error_count = 0;
12475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->recvbuf_length = (ps_recv_pkt->llcbuf_len -
12495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    PH_LLCNFC_LEN_APPEND);
12505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void)memcpy ((void *)psLlcCtxt->precv_buf, (void *)(
12525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_recv_pkt->s_llcbuf.sllcpayload.llcpayload),
12535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psLlcCtxt->recvbuf_length);
12545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if defined (LLC_SEND_RR_ACK)
12565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (((ns_index < ps_frame_info->n_r) &&
12585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ((ps_frame_info->n_r - ns_index) < ps_frame_info->window_size))
12595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            || ((ns_index > ps_frame_info->n_r) &&
12605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ((ns_index - ps_frame_info->n_r) > ps_frame_info->window_size)))
12615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->n_r = ((ns_index + 1)
12635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                % PH_LLCNFC_MOD_NS_NR);
12645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
12665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if defined (LLC_SEND_RR_ACK) */
12685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Update the N(R) value in I and S frame context  */
12705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->n_r = ((ps_frame_info->n_r + 1)
12715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    % PH_LLCNFC_MOD_NS_NR);
12725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1273b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas#ifdef PIGGY_BACK
1274b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            ps_frame_info->resp_recvd_count = (uint8_t)
1275b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                                    (ps_frame_info->resp_recvd_count + 1);
1276b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas#endif /* #ifdef PIGGY_BACK */
1277b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas
12785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_BUSY == PHNFCSTATUS (ps_frame_info->write_status))
12815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Any how write cannot be done and some frame is ready to be sent
12835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            so this frame will act as the ACK */
12845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_WriteWaitCall (psLlcCtxt);
12855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
12875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (
12895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (ps_frame_info->n_s != ((ps_store_frame->winsize_cnt +
12905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_store_frame->start_pos) % PH_LLCNFC_MOD_NS_NR))
12915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                )
12925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
12935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* If user has sent a frame and DAL write is busy, then
12945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                it has to be sent */
12955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_H_SendUserIFrame (psLlcCtxt, ps_store_frame);
12965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
12975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_PENDING == result)
13005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            dont_send_s_frame = TRUE;
13025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB
13035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLlcNfc_H_SendInfo (psLlcCtxt);
13045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */
13055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
13075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            cmdtype = phLlcNfc_e_rr;
13095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* If i frame is sent from the stored list, it got the correct
13105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                acknowledge i frame, so now for an i frame , s frame acknowledge
13115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                is sent */
13125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            eframe_type = ((resend_i_frame == ps_frame_info->sent_frame_type)?
13135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            resend_s_frame : s_frame);
13145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1316b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas#ifdef PIGGY_BACK
13175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLlcNfc_H_SendInfo (psLlcCtxt);
1318b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas#endif /* #ifdef PIGGY_BACK */
13195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
13215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
13225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
13235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_frame_info->send_error_count = (uint8_t)
13245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (ps_frame_info->send_error_count + 1);
13255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_SEND_ERROR_COUNT
13275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (ps_frame_info->send_error_count < RECV_ERROR_FRAME_COUNT)
13295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_SEND_ERROR_COUNT */
13315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_RR_INSTEAD_OF_REJ
13345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (((ps_frame_info->n_r > 0) && (ns_index == (ps_frame_info->n_r - 1)))
133634ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly                || ((0 == ps_frame_info->n_r) &&
133734ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly                (ns_index == (PH_LLCNFC_MOD_NS_NR - 1))))
13385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
13395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                cmdtype = phLlcNfc_e_rr;
13405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                eframe_type = rej_rr_s_frame;
13415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
13425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
13435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_RR_INSTEAD_OF_REJ */
13455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
13465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                cmdtype = phLlcNfc_e_rej;
13475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                eframe_type = ((resend_i_frame == ps_frame_info->sent_frame_type)?
13485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                resend_rej_s_frame : reject_s_frame);
13495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
13505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_SEND_ERROR_COUNT
13535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
13545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_RSET_INSTEAD_OF_EXCEPTION
13565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_SendRSETFrame (psLlcCtxt);
13585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else /* #ifdef LLC_RSET_INSTEAD_OF_EXCEPTION */
13605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            dont_send_s_frame = TRUE;
13625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PH_LLCNFC_DEBUG("SEND ERROR COUNT : 0x%02X\n", ps_frame_info->send_error_count);
13635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Error count has reached the limit, raise exception */
13645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC,
13655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            NFCSTATUS_BOARD_COMMUNICATION_ERROR);
13665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
13675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1);
13685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if 0 */
13695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Resend done, no answer from the device */
13705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psLlcCtxt->cb_for_if.notify (
13715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            psLlcCtxt->cb_for_if.pif_ctxt,
13725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            psLlcCtxt->phwinfo,
13735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFC_NOTIFY_DEVICE_ERROR,
13745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            &notifyinfo);
13755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_RSET_INSTEAD_OF_EXCEPTION */
13775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_SEND_ERROR_COUNT */
13795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
13805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_RELEASE_FLAG
13825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (FALSE == g_release_flag)
13845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_RELEASE_FLAG */
13865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1387b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        (void)phLlcNfc_Interface_Read(psLlcCtxt,
13885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_READWAIT_OFF,
13895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &(ps_recv_pkt->s_llcbuf.llc_length_byte),
13905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (uint8_t)PH_LLCNFC_BYTES_INIT_READ);
13915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1392b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas#ifdef PIGGY_BACK
1393b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        /* Check if any write call is performed or not */
1394b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        if (NFCSTATUS_PENDING != result)
1395b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        {
1396b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            /* No write is performed, So, now check */
1397b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            if (NFCSTATUS_BUSY == PHNFCSTATUS (ps_frame_info->write_status))
1398b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            {
1399b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                /* Any how write cannot be done and some frame is ready to be sent
1400b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                so this frame will act as the ACK */
1401b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                result = phLlcNfc_H_WriteWaitCall (psLlcCtxt);
1402b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            }
1403b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        }
1404b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas
1405b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        if (NFCSTATUS_PENDING != result)
1406b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        {
1407b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            if (ps_frame_info->window_size == ps_frame_info->resp_recvd_count)
1408b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            {
1409b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                phLlcNfc_LlcPacket_t    s_packet_info;
1410b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                /* Create S frame */
1411b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                (void)phLlcNfc_H_CreateSFramePayload (ps_frame_info, &(s_packet_info), cmdtype);
14125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1413b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                result = phLlcNfc_Interface_Write(psLlcCtxt,
1414b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint8_t *)&(s_packet_info.s_llcbuf),
1415b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint32_t)(s_packet_info.llcbuf_len));
1416b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas
1417b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas
1418b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                if (0 == ps_frame_info->send_error_count)
1419b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                {
1420b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                    ps_frame_info->write_wait_call = invalid_frame;
1421b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                }
1422b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                ps_frame_info->sent_frame_type = eframe_type;
1423b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            }
1424b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            else
1425b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            {
1426b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                result = phLlcNfc_StartTimers (PH_LLCNFC_ACKTIMER, 0);
1427b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            }
1428b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        }
1429b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas#else /* #ifdef PIGGY_BACK */
14305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if ((TRUE != ps_frame_info->write_pending) &&
14325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (PH_LLCNFC_READPEND_REMAIN_BYTE != ps_frame_info->read_pending) &&
14335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (FALSE == dont_send_s_frame))
14345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1435b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            phLlcNfc_LlcPacket_t    s_packet_info = {0};
14365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Create S frame */
1437b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas            (void)phLlcNfc_H_CreateSFramePayload (ps_frame_info, &(s_packet_info), cmdtype);
14385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_Interface_Write(psLlcCtxt,
1440b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                        (uint8_t *)&(s_packet_info.s_llcbuf),
1441b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                        (uint32_t)(s_packet_info.llcbuf_len));
14425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (0 == ps_frame_info->send_error_count)
14455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
14465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_wait_call = invalid_frame;
14475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
14485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->sent_frame_type = eframe_type;
14495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1450b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas#endif /* #ifdef PIGGY_BACK */
14515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
14525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return ;
14545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
14555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
14575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
14585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ProcessUFrame (
14595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt
14605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
14615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
14625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
14635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t            *ps_frame_info = NULL;
14645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t        *ps_uframe_pkt = NULL;
14655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_URSET_NO_DELAY
146634ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly    phNfc_sCompletionInfo_t     notifyinfo = {0,0,0};
14675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else /* #ifdef LLC_URSET_NO_DELAY */
14685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint32_t                    delay_timer_id =
14695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_OSALNFC_INVALID_TIMER_ID;
14705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_URSET_NO_DELAY */
14715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     cmdtype = phLlcNfc_e_error;
14725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StopTimers(PH_LLCNFC_CONNECTIONTIMER, 0);
14745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_frame_info = &(psLlcCtxt->s_frameinfo);
14755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_uframe_pkt = &(ps_frame_info->s_recvpacket);
14765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Check the command type */
14775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    cmdtype = (ps_uframe_pkt->s_llcbuf.sllcpayload.llcheader &
14785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_U_FRAME_MODIFIER_MASK);
14795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PHNFC_UNUSED_VARIABLE(result);
14805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    switch(cmdtype)
14815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
14825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case phLlcNfc_e_rset:
14835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
14845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psLlcCtxt->s_frameinfo.rset_recvd = TRUE;
14855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* command type is RSET, so update the U frame parameters */
14865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_Update_ReceivedRSETInfo (ps_frame_info,
14875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                ps_uframe_pkt->s_llcbuf.sllcpayload);
14885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Create a UA frame */
14895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_CreateUFramePayload(psLlcCtxt,
14905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            ps_uframe_pkt,
14915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            &(ps_uframe_pkt->llcbuf_len),
14925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            phLlcNfc_e_ua);
14935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NFCSTATUS_SUCCESS == result)
14955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
14965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Call DAL write */
14975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_Interface_Write( psLlcCtxt,
14985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (uint8_t*)&(ps_uframe_pkt->s_llcbuf),
14995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (uint32_t)ps_uframe_pkt->llcbuf_len);
15005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phLlcNfc_H_ResetFrameInfo(psLlcCtxt);
15025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_status = result;
15035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->write_wait_call = invalid_frame;
15045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (NFCSTATUS_PENDING == result)
15055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
15065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->sent_frame_type =
15075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((ps_frame_info->sent_frame_type != init_u_rset_frame) ?
15085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            u_a_frame : init_u_a_frame);
15095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
15105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
15115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
15125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if (NFCSTATUS_BUSY == PHNFCSTATUS(result))
15135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
15145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        ps_frame_info->write_wait_call =
15155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((ps_frame_info->sent_frame_type != init_u_rset_frame) ?
15165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            u_a_frame : init_u_a_frame);
15175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        result = NFCSTATUS_PENDING;
15185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
15195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
15205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
15215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
15225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
15235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case phLlcNfc_e_ua:
15245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
15255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLlcNfc_H_ResetFrameInfo (psLlcCtxt);
15265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Add timer here, to delay the next command to the PN544 */
15275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_URSET_NO_DELAY
15285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (ps_frame_info->s_send_store.winsize_cnt > 0)
15295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
15305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
15315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Resend I frame */
15325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_H_SendTimedOutIFrame (psLlcCtxt,
15335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                &(ps_frame_info->s_send_store, 0);
15345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
15355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_H_SendUserIFrame (psLlcCtxt,
15365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                &(ps_frame_info->s_send_store));
15375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if 0 */
15385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
15395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
15405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
15415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if ((init_u_rset_frame == ps_frame_info->sent_frame_type) &&
15425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (NULL != psLlcCtxt->cb_for_if.notify))
15435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
15445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_frame_info->sent_frame_type = write_resp_received;
15455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    notifyinfo.status = NFCSTATUS_SUCCESS;
15465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Send the notification to the upper layer */
15475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psLlcCtxt->cb_for_if.notify(
15485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psLlcCtxt->cb_for_if.pif_ctxt,
15495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psLlcCtxt->phwinfo,
15505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFC_NOTIFY_INIT_COMPLETED,
15515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                &notifyinfo);
15525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
15535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
15545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else /* #ifdef LLC_URSET_NO_DELAY */
15555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            delay_timer_id = phOsalNfc_Timer_Create ();
15565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phOsalNfc_Timer_Start (delay_timer_id, LLC_URSET_DELAY_TIME_OUT,
15575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    phLlcNfc_URSET_Delay_Notify, (void*)0);
15585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_URSET_NO_DELAY */
15595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
15605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
15615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        default:
15625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
15635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = PHNFCSTVAL(CID_NFC_LLC,
15645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_INVALID_FORMAT);
15655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
15665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
15675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
15685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
15695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
15705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
15725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
15735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ProcessSFrame (
15745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt)
15755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
15765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
15775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     cmdtype = phLlcNfc_e_error;
15785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
15795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                prev_win_count = 0;
15805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if 0 */
158134ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly    phNfc_sTransactionInfo_t    compinfo = {0, 0, 0, 0, 0};
15825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t            *ps_frame_info = NULL;
15835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t      *ps_store_frame = NULL;
15845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t        *ps_recv_pkt = NULL;
15855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     no_of_del_frames = 0;
158634ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly    phNfc_sCompletionInfo_t     notifyinfo = {0,0,0};
15875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_frame_info = &(psLlcCtxt->s_frameinfo);
15895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_recv_pkt = &(ps_frame_info->s_recvpacket);
15905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_store_frame = &(ps_frame_info->s_send_store);
15915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    cmdtype = (ps_recv_pkt->s_llcbuf.sllcpayload.llcheader &
15935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_S_FRAME_TYPE_MASK);
15945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PHNFC_UNUSED_VARIABLE(result);
15955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("NS START POS BEFORE DEL : 0x%02X\n", ps_store_frame->start_pos);
15975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("WIN SIZE BEFORE DEL : 0x%02X\n", ps_store_frame->winsize_cnt);
15985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Correct frame is received, so remove the
16005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        stored i frame info for the acknowledged frames */
16015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    no_of_del_frames = phLlcNfc_H_UpdateIFrameList (ps_frame_info,
16025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        &(ps_frame_info->s_send_store));
16035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("NS START POS AFTER DEL : 0x%02X\n", ps_store_frame->start_pos);
16055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG("WIN SIZE AFTER DEL : 0x%02X\n", ps_store_frame->winsize_cnt);
16065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
16085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    prev_win_count = ps_frame_info->s_send_store.winsize_cnt;
16095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if 0 */
16105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Pend the read */
16125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    result = phLlcNfc_Interface_Read (psLlcCtxt,
16135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            PH_LLCNFC_READWAIT_OFF,
16145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            &(ps_recv_pkt->s_llcbuf.llc_length_byte),
16155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (uint8_t)PH_LLCNFC_BYTES_INIT_READ);
16165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    switch(cmdtype)
16175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
16185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case phLlcNfc_e_rr:
16195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case phLlcNfc_e_rej:
16205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
16215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* RR frame received */
16225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLlcNfc_StopTimers (PH_LLCNFC_GUARDTIMER, no_of_del_frames);
16235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (phLlcNfc_e_rr == cmdtype)
16255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->recv_error_count = 0;
16275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->send_error_count = 0;
16285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
16305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ps_frame_info->recv_error_count = (uint8_t)
16325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (ps_frame_info->recv_error_count + 1);
16335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (ps_frame_info->recv_error_count >= RECV_ERROR_FRAME_COUNT)
16365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Do nothing */
16385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else if (NFCSTATUS_BUSY == PHNFCSTATUS(ps_frame_info->write_status))
16405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_H_WriteWaitCall (psLlcCtxt);
16425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
16445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (
16465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (ps_frame_info->n_s != ((ps_store_frame->winsize_cnt +
16475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    ps_store_frame->start_pos) % PH_LLCNFC_MOD_NS_NR))
16485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    )
16495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
16505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* If user has sent a frame and DAL write is busy, then
16515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        it has to be sent */
16525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    result = phLlcNfc_H_SendUserIFrame (psLlcCtxt, ps_store_frame);
16535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
16545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if ((0 != psLlcCtxt->send_cb_len) &&
16575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (ps_store_frame->winsize_cnt < ps_frame_info->window_size))
16585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Due to the window size count (i.e., count has reached
16605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    the limit), send completion was not sent for the previous
16615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    send from the upper layer. So to allow next send from the
16625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    upper layer, send completion is called */
16635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                compinfo.length = (uint16_t)psLlcCtxt->send_cb_len;
16645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                compinfo.status = NFCSTATUS_SUCCESS;
16655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (NULL != psLlcCtxt->cb_for_if.send_complete)
16675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
16685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psLlcCtxt->send_cb_len = 0;
16695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Call the send callback, if the window size
16705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        count becomes less than actual window size */
16715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psLlcCtxt->cb_for_if.send_complete (
16725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psLlcCtxt->cb_for_if.pif_ctxt,
16735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psLlcCtxt->phwinfo, &compinfo);
16745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
16755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
16775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
16785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
16805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case phLlcNfc_e_rej:
16815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
16825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->recv_error_count = (uint8_t)
16835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (ps_frame_info->recv_error_count + 1);
16845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* RR frame received */
16855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLlcNfc_StopTimers (PH_LLCNFC_GUARDTIMER, no_of_del_frames);
16865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (ps_frame_info->recv_error_count < RECV_ERROR_FRAME_COUNT)
16885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Below check is added because if PN544 sends REJ to a frame, but
16905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    the next frame has already been sent from PN544, then
16915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Send the user I frame */
16925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_H_SendUserIFrame (psLlcCtxt, ps_store_frame);
16935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
16955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
16965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if 0 */
16975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case phLlcNfc_e_rnr:
16995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
17005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLlcNfc_StopAllTimers ();
17015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->recv_error_count = (uint8_t)
17025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (ps_frame_info->recv_error_count + 1);
17035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
17045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
17055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case phLlcNfc_e_srej:
17075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        default:
17085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
17095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->recv_error_count = (uint8_t)
17105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (ps_frame_info->recv_error_count + 1);
17115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = PHNFCSTVAL (CID_NFC_LLC,
17125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_INVALID_FORMAT);
17135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
17145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
17155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
17165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (ps_frame_info->recv_error_count >= RECV_ERROR_FRAME_COUNT)
17185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
17195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_RSET_INSTEAD_OF_EXCEPTION
17205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = phLlcNfc_H_SendRSETFrame (psLlcCtxt);
17225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else /* #ifdef LLC_RSET_INSTEAD_OF_EXCEPTION */
17245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PH_LLCNFC_DEBUG("RECV ERROR COUNT : 0x%02X\n", ps_frame_info->recv_error_count);
17265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Raise the exception for CRC error received from the  */
17275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC,
17285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_BOARD_COMMUNICATION_ERROR);
17295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
17305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1);
17315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if 0 */
17325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Resend done, no answer from the device */
17335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->cb_for_if.notify (
17345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psLlcCtxt->cb_for_if.pif_ctxt,
17355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psLlcCtxt->phwinfo,
17365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NFC_NOTIFY_DEVICE_ERROR,
17375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &notifyinfo);
17385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef LLC_RSET_INSTEAD_OF_EXCEPTION */
17405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
17415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return ;
17435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
17445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
17475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ComputeCrc(
17485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     *pData,
17495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     length,
17505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     *pCrc1,
17515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     *pCrc2
17525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
17535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
17545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     crc_byte = 0,
17555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                index = 0;
17565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint16_t    crc = 0;
17575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef CRC_A
17595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        crc = 0x6363; /* ITU-V.41 */
17605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
17615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        crc = 0xFFFF; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
17625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef CRC_A */
17635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    do
17655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
17665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        crc_byte = pData[index];
17675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLlcNfc_H_UpdateCrc(crc_byte, &crc);
17685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        index++;
17695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } while (index < length);
17705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef INVERT_CRC
17725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    crc = ~crc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
17735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifndef INVERT_CRC */
17745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    *pCrc1 = (uint8_t) (crc & 0xFF);
17765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    *pCrc2 = (uint8_t) ((crc >> 8) & 0xFF);
17775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
17785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
17795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
17815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
17825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_UpdateCrc(
17835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     crcByte,
17845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint16_t    *pCrc
17855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
17865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
17875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    crcByte = (crcByte ^ (uint8_t)((*pCrc) & 0x00FF));
17885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    crcByte = (crcByte ^ (uint8_t)(crcByte << 4));
17895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    *pCrc = (*pCrc >> 8) ^ ((uint16_t)crcByte << 8) ^
17905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ((uint16_t)crcByte << 3) ^
17915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ((uint16_t)crcByte >> 4);
17925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
17935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
17955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_StoreIFrame (
17965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t      *psList,
17975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t        sPacketInfo
17985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
17995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
18005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   result = NFCSTATUS_SUCCESS;
18015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     ns_index = 0,
18025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                llc_header = 0;
18035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((NULL == psList) || (0 == sPacketInfo.llcbuf_len) ||
18055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (PH_LLCNFC_I_HEADER_INIT !=
18065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (sPacketInfo.s_llcbuf.sllcpayload.llcheader &
18075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PH_LLCNFC_I_FRM_HEADER_MASK)))
18085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
18095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_PARAMETER);
18105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
18115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
18125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
18135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Get the index from the start index */
18145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(psList->winsize_cnt > 0)
18155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
18165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ns_index = (uint8_t)((psList->start_pos + psList->winsize_cnt) %
18175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_LLCNFC_MOD_NS_NR);
18185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
18195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
18205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
18215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ns_index = psList->start_pos;
18225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
18235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        llc_header = (uint8_t)(PH_LLCNFC_I_HEADER_INIT | (ns_index <<
18255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        PH_LLCNFC_NS_START_BIT_POS));
18265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        sPacketInfo.s_llcbuf.sllcpayload.llcheader = llc_header;
18275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void)memcpy (&(psList->s_llcpacket[ns_index]),
18295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &(sPacketInfo), sizeof(phLlcNfc_LlcPacket_t));
18305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* This variable says that LLC has to send complete
18325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            callback for stored I frame */
18335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psList->s_llcpacket[ns_index].frame_to_send = invalid_frame;
18345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psList->winsize_cnt++;
18365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
18375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
18385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
18395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
18415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
18425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_DeleteIFrame (
18435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t      *psList
18445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
18455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
18465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (NULL != psList)
18475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
18485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void)memset( &(psList->s_llcpacket[psList->start_pos]),
18495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        0, sizeof(phLlcNfc_LlcPacket_t));
18505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Go to next N(S) position */
18525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psList->start_pos = ((psList->start_pos + 1) %
18535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            PH_LLCNFC_MOD_NS_NR);
18545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (psList->winsize_cnt > 0)
18565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
18575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psList->winsize_cnt--;
18585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
18595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
18605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
18615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
18635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
18645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_IFrameList_Peek (
18655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t      *psList,
18665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_LlcPacket_t        **psPacketinfo,
18675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     position
18685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
18695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
18705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   result = NFCSTATUS_SUCCESS;
18715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t     index = 0;
18725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    *psPacketinfo = NULL;
18745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((NULL != psList) && (psList->winsize_cnt > 0))
18755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
18765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = NFCSTATUS_SUCCESS;
18775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if ((position < (psList->start_pos + psList->winsize_cnt)) ||
18785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (DEFAULT_PACKET_INPUT == position))
18795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
18805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            index = (uint8_t)((DEFAULT_PACKET_INPUT == position) ?
18815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psList->start_pos : position);
18825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            *psPacketinfo = &(psList->s_llcpacket[index]);
18835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
18845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
18855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
18875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
18885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
18895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
18905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ProRecvFrame (
18915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t      *psLlcCtxt
18925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
18935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
18945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               result = PHNFCSTVAL(CID_NFC_LLC,
18955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    NFCSTATUS_INVALID_PARAMETER);
18965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_FrameType_t    frame_type = phLlcNfc_eErr_frame;
18975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef LLC_DATA_BYTES
18985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 *print_buf = (uint8_t *)
18995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            &(psLlcCtxt->s_frameinfo.s_recvpacket.s_llcbuf);
19005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 buf_len =
19015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            psLlcCtxt->s_frameinfo.s_recvpacket.llcbuf_len;
19025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_STRING("** Response ");
19035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* LLC_DATA_BYTES */
19055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (NULL != psLlcCtxt)
19065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
19075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = NFCSTATUS_SUCCESS;
19085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Get the received frame type */
19095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        frame_type = phLlcNfc_H_ChkGetLlcFrameType(
19105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psLlcCtxt->s_frameinfo.s_recvpacket.s_llcbuf.sllcpayload.llcheader);
19115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Depending on the received frame type, process the
19135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        received buffer */
19145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        switch(frame_type)
19155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
19165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phLlcNfc_eU_frame:
19175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
19185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_PRINT("U frame received \n");
19195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_STRING("U frame ");
19205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_PRINT_DATA(print_buf, buf_len);
19215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_STRING(";\n");
19225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = phLlcNfc_H_ProcessUFrame(psLlcCtxt);
19235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
19245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
19255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phLlcNfc_eI_frame:
19265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
19275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_PRINT("I frame received \n");
19285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_STRING("I frame ");
19295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_PRINT_DATA(print_buf, buf_len);
19305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_STRING(";\n");
19315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phLlcNfc_H_ProcessIFrame(psLlcCtxt);
19325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
19335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
19345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phLlcNfc_eS_frame:
19355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
19365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_PRINT("S frame received \n");
19375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_STRING("S frame ");
19385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_PRINT_DATA(print_buf, buf_len);
19395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_STRING(";\n");
19405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phLlcNfc_H_ProcessSFrame(psLlcCtxt);
19415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
19425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
19435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phLlcNfc_eErr_frame:
19445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            default:
19455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
19465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PH_LLCNFC_PRINT("Error frame received \n");
19475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_FORMAT);
19485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
19495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
19505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
19515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
19535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
19545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
19555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef CRC_ERROR_REJ
19575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
19585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_SendRejectFrame(
19595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      phLlcNfc_Context_t  *psLlcCtxt
19605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      )
19615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
19625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS       result = NFCSTATUS_SUCCESS;
1963b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    phLlcNfc_LlcPacket_t    s_packet_info = {0};
1964b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas
19655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    result = phLlcNfc_H_CreateSFramePayload(
1966b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                                    &(psLlcCtxt->s_frameinfo),
1967b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                                    &(s_packet_info),
19685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    phLlcNfc_e_rej);
19695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Send the "S" frame to the lower layer */
19705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    result = phLlcNfc_Interface_Write(psLlcCtxt,
1971b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        (uint8_t *)&(s_packet_info.s_llcbuf),
1972b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        (uint32_t)(s_packet_info.llcbuf_len));
19735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (NFCSTATUS_PENDING == result)
19755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
19765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Increment the retry count of the reject frame */
19775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.recv_error_count =
19785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (psLlcCtxt->s_frameinfo.recv_error_count + 1);
19795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
19805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
19835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
19845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef CRC_ERROR_REJ */
19855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
19865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
19875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid
19885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_ResetFrameInfo (
19895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t  *psLlcCtxt
19905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly)
19915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
19925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                     i = 0,
19935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                win_cnt = 0,
19945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                pos = 0,
19955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                while_exit = FALSE,
19965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                index_flag = FALSE;
19975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t      *ps_send_store = NULL;
19985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Buffer_t           *ps_buffer = NULL;
19995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_send_store = &(psLlcCtxt->s_frameinfo.s_send_store);
20015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    win_cnt = ps_send_store->winsize_cnt;
20025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pos = ps_send_store->start_pos;
20035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_PRINT ("\n\nLLC : phLlcNfc_H_ResetFrameInfo called\n\n");
20045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG ("\n\nLLC : ps_send_store->start_pos %08X\n", ps_send_store->start_pos);
20055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG ("\n\nLLC : ps_send_store->winsize_cnt before reset %08X\n", ps_send_store->winsize_cnt);
20065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (0 != pos)
20095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
20105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* If the start position of the ns = 0, then
20115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            no need to shift the stored llc data,
20125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Else it has to be shifted to the first
20135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            index of the array */
20145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(TRUE == ((pos + win_cnt) /
20155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PH_LLCNFC_MAX_I_FRAME_STORE))
20165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
20175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* 'i' is the array index, So to store data in the array,
20185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                windows size count shall be subtracted by 1 */
20195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            i = (win_cnt - 1);
20205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* if window size > 1 and ns for 2 frames are 7 and 0, then
20215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                to reset the ns index to 0, the frames are copied from
20225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                the reverse order, so to do it a flag is declared */
20235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            index_flag = TRUE;
20245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pos = (((pos - 1) + win_cnt) % PH_LLCNFC_MAX_I_FRAME_STORE);
20255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
20265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        while (FALSE == while_exit)
20285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
20295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (void)memcpy ((void *)&(ps_send_store->s_llcpacket[i]),
20305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)&(ps_send_store->s_llcpacket[pos]),
20315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof (phLlcNfc_LlcPacket_t));
20325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_send_store->s_llcpacket[i].frame_to_send = invalid_frame;
20345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_buffer = &(ps_send_store->s_llcpacket[i].s_llcbuf);
20365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* change n(s) value */
20375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_buffer->sllcpayload.llcheader = (uint8_t)
20385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (PH_LLCNFC_I_HEADER_INIT |
20395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (i << PH_LLCNFC_NS_START_BIT_POS));
20405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(TRUE == index_flag)
20415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
20425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(0 == i)
20435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
20445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    while_exit = TRUE;
20455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
20465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
20475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
20485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    i = ((i - 1) % PH_LLCNFC_MAX_I_FRAME_STORE);
20495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if (0 == pos)
20505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
20515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pos = (PH_LLCNFC_MAX_I_FRAME_STORE - 1);
20525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
20535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    else
20545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
20555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pos = ((pos - 1) % PH_LLCNFC_MAX_I_FRAME_STORE);
20565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
20575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
20585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
20595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
20605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
20615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (i >= win_cnt)
20625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
20635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    while_exit = TRUE;
20645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
20655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
20665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
20675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    i = ((i + 1) % PH_LLCNFC_MAX_I_FRAME_STORE);
20685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    pos = ((pos + 1) % PH_LLCNFC_MAX_I_FRAME_STORE);
20695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
20705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
20725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
20735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
20745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    psLlcCtxt->s_timerinfo.guard_to_count = 0;
20755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    psLlcCtxt->s_timerinfo.timer_flag = 0;
20765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_send_store->start_pos = 0;
20775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    psLlcCtxt->s_frameinfo.n_r = psLlcCtxt->s_frameinfo.n_s = 0;
20785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (ps_send_store->winsize_cnt > 0)
20795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
20805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.rejected_ns = 0;
20815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
20825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
20835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
20845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psLlcCtxt->s_frameinfo.rejected_ns = DEFAULT_PACKET_INPUT;
20855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
20865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG ("\n\nLLC : ps_send_store->winsize_cnt after reset %08X\n", ps_send_store->winsize_cnt);
20885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
20895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
20905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
20915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
20925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_WriteWaitCall (
20935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Context_t  *psLlcCtxt
20945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    )
20955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
20965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
20975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_StoreIFrame_t      *ps_store_info = NULL;
20985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t            *ps_frame_info = NULL;
20995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_frame_info = &(psLlcCtxt->s_frameinfo);
21015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_store_info = &(ps_frame_info->s_send_store);
21025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_PRINT ("\nLLC : phLlcNfc_H_WriteWaitCall call ..\n");
21045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG ("\n\nLLC : ps_frame_info->write_wait_call before call %08X\n", ps_frame_info->write_wait_call);
21055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_frame_info->write_status = NFCSTATUS_PENDING;
21075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    switch (ps_frame_info->write_wait_call)
21085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
21095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case user_i_frame:
21105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
21115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_wait_call = invalid_frame;
21125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_SendUserIFrame (psLlcCtxt, ps_store_info);
21135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
21145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
21155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case resend_i_frame:
21175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
21185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_wait_call = invalid_frame;
21195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_SendTimedOutIFrame (psLlcCtxt, ps_store_info, 0);
21205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
21215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
21225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case rejected_i_frame:
21245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
21255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_wait_call = invalid_frame;
21265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_SendRejectedIFrame (psLlcCtxt, ps_store_info,
21275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    ps_frame_info->rejected_ns);
21285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
21295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
21305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case resend_s_frame:
21325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case reject_s_frame:
21335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case resend_rej_s_frame:
21345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
21355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_wait_call = invalid_frame;
21365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
21375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
21385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case u_rset_frame:
21405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
21415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_wait_call = invalid_frame;
21425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = phLlcNfc_H_SendRSETFrame (psLlcCtxt);
21435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
21445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
21455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        default :
21475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
21485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->write_wait_call = invalid_frame;
21495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
21505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
21515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
21525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_DEBUG ("\n\nLLC : ps_frame_info->write_wait_call after call %08X\n", ps_frame_info->write_wait_call);
21545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    PH_LLCNFC_PRINT ("\nLLC : phLlcNfc_H_WriteWaitCall end ..\n");
21555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
21565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
21575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
21595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLlcNfc_H_SendRSETFrame (
21605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      phLlcNfc_Context_t  *psLlcCtxt
21615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      )
21625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
21635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
2164b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    phLlcNfc_LlcPacket_t        s_packet_info;
21655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLlcNfc_Frame_t            *ps_frame_info = NULL;
21665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_frame_info = &(psLlcCtxt->s_frameinfo);
21685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2169b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas    result = phLlcNfc_H_CreateUFramePayload(psLlcCtxt,
2170b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                                    &(s_packet_info),
2171b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                                    &(s_packet_info.llcbuf_len),
21725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    phLlcNfc_e_rset);
21735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (NFCSTATUS_SUCCESS == result)
21755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
21765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Call DAL write */
2177b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas        result = phLlcNfc_Interface_Write(psLlcCtxt,
2178b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint8_t*)&(s_packet_info.s_llcbuf),
2179b313c3d09c64c31439332e88e0aca676ae1858b5Daniel Tomas                            (uint32_t)s_packet_info.llcbuf_len);
21805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
21815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    ps_frame_info->write_status = result;
21835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if (NFCSTATUS_PENDING == result)
21845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
21855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Start the timer */
21865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        result = phLlcNfc_StartTimers (PH_LLCNFC_CONNECTIONTIMER, 0);
21875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == result)
21885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
21895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ps_frame_info->sent_frame_type = u_rset_frame;
21905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            result = NFCSTATUS_PENDING;
21915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
21925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
21935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
21945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
21955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ps_frame_info->write_wait_call = u_rset_frame;
21965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
21975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
21985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return result;
21995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
22005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
22015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2202