static NFCSTATUS phFriNfc_MfUL_UpdateAndWriteLockBits ( phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt) { NFCSTATUS result = NFCSTATUS_SUCCESS; phFriNfc_Type2_AddInfo_t *ps_type2_info = &(NdefSmtCrdFmt->AddInfo.Type2Info); uint8_t byte_index = 0; uint8_t no_of_bits_left_in_block = 0; uint8_t remaining_lock_bits = 0; uint8_t remaining_lock_bytes = 0; /* Array of 3 is used because the lock bits with 4 bytes in a block is handled in the function phFriNfc_MfUL_ReadWriteLockBytes So use this function only if lock bytes doesnt use the entire block */ uint8_t lock_bytes_value[MFUL_BLOCK_SIZE_IN_BYTES] = {0}; uint8_t lock_byte_index = 0; (void)phOsalNfc_MemCopy ((void *)lock_bytes_value, (void*)(ps_type2_info->ReadData + ps_type2_info->ReadDataIndex), sizeof (ps_type2_info->DynLockBytes)); remaining_lock_bits = phFriNfc_MfUL_CalcRemainingLockBits (NdefSmtCrdFmt); if (ps_type2_info->CurrentBlock == ps_type2_info->LockBlockNumber) { /* 1st write to lock bits, so byte_index is updated */ byte_index = ps_type2_info->LockByteNumber; } no_of_bits_left_in_block = (uint8_t)((MFUL_BLOCK_SIZE_IN_BYTES - byte_index) * MFUL_BYTE_SIZE_IN_BITS); if (no_of_bits_left_in_block >= remaining_lock_bits) { /* Entire lock bits can be written if block size is more than number of lock bits. so allocate the lock bits with value 1b and dont change the remaining bits */ if (remaining_lock_bits % MFUL_BYTE_SIZE_IN_BITS) { /* mod operation has resulted in a value, means lock bits ends in between a byte */ uint8_t mod_value = 0; remaining_lock_bytes = ((remaining_lock_bits / MFUL_BYTE_SIZE_IN_BITS) + 1); /* mod_value is used to fill the only partial bits and remaining bits shall be untouched */ mod_value = (uint8_t)(remaining_lock_bits % MFUL_BYTE_SIZE_IN_BITS); if (remaining_lock_bits > MFUL_BYTE_SIZE_IN_BITS) { /* lock bits to write is greater than 8 bits */ while (lock_byte_index < (remaining_lock_bytes - 1)) { /* Set 1b to all bits left in the block */ lock_bytes_value[byte_index] = 0xFF; lock_byte_index = (uint8_t)(lock_byte_index + 1); byte_index = (uint8_t)(byte_index + 1); } /* Last byte of the lock bits shall be filled partially, Set only the remaining lock bits and dont change the other bit value */ lock_bytes_value[byte_index] = 0; lock_bytes_value[byte_index] = (uint8_t) SET_BITS8 (lock_bytes_value[byte_index], 0, mod_value, 1); } else { /* lock bits to write is less than 8 bits, so there is only one byte to write. Set only the remaining lock bits and dont change the other bit value */ lock_bytes_value[0] = (uint8_t)SET_BITS8 (lock_bytes_value[0], 0, mod_value, 1); } } /* if (remaining_lock_bits % MFUL_BYTE_SIZE_IN_BITS) */ else { /* MOD operation is 00, that means entire byte value shall be 0xFF, means every bit shall be to 1 */ remaining_lock_bytes = (remaining_lock_bits / MFUL_BYTE_SIZE_IN_BITS); while (lock_byte_index < remaining_lock_bytes) { /* Set 1b to all bits left in the block */ lock_bytes_value[byte_index] = 0xFF; lock_byte_index = (uint8_t)(lock_byte_index + 1); byte_index = (uint8_t)(byte_index + 1); } } /* else of if (remaining_lock_bits % MFUL_BYTE_SIZE_IN_BITS) */ ps_type2_info->LockBitsWritten = (uint8_t)(ps_type2_info->LockBitsWritten + remaining_lock_bits); } /* if (no_of_bits_left_in_block >= remaining_lock_bits) */ else { /* Update till the left bits in the block and then carry out next operation after this write */ while (lock_byte_index < (no_of_bits_left_in_block / MFUL_BYTE_SIZE_IN_BITS)) { /* Set 1b to all bits left in the block */ lock_bytes_value[byte_index] = 0xFF; lock_byte_index = (uint8_t)(lock_byte_index + 1); byte_index = (uint8_t)(byte_index + 1); } ps_type2_info->LockBitsWritten = (uint8_t)(ps_type2_info->LockBitsWritten + no_of_bits_left_in_block); } /* else of if (no_of_bits_left_in_block >= remaining_lock_bits) */ /* Copy the values back to the DynLockBytes structure member */ (void)phOsalNfc_MemCopy ((void*)ps_type2_info->DynLockBytes, (void *)lock_bytes_value, sizeof (ps_type2_info->DynLockBytes)); NdefSmtCrdFmt->State = PH_FRINFC_MFUL_FMT_RO_WR_DYN_LOCK_BYTES; result = phFriNfc_MfUL_H_WrRd (NdefSmtCrdFmt); return result; }
void phLlcNfc_StopTimers ( uint8_t TimerType, uint8_t no_of_guard_to_del ) { NFCSTATUS result = NFCSTATUS_SUCCESS; #ifdef LLC_TIMER_ENABLE uint32_t timerid = 0, timerflag = FALSE; uint8_t timer_count = 0; phLlcNfc_Timerinfo_t *ps_timer_info = NULL; ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo); timerflag = ps_timer_info->timer_flag; PHNFC_UNUSED_VARIABLE (result); PH_LLCNFC_PRINT("\n\nLLC : STOP TIMER CALLED\n\n"); switch(TimerType) { case PH_LLCNFC_CONNECTIONTIMER: { ps_timer_info->timer_flag = (uint8_t) SET_BITS8(ps_timer_info->timer_flag, PH_LLCNFC_CON_TO_BIT, PH_LLCNFC_TO_NOOFBITS, 0); timerid = ps_timer_info->timer_id [PH_LLCNFC_CONNECTION_TO_INDEX]; break; } case PH_LLCNFC_GUARDTIMER: { uint8_t start_index = 0; timer_count = ps_timer_info->guard_to_count; PH_LLCNFC_DEBUG("GUARD TIMER COUNT BEFORE DELETE: 0x%02X\n", timer_count); PH_LLCNFC_DEBUG("GUARD TIMER TO DELETE: 0x%02X\n", no_of_guard_to_del); if (timer_count > no_of_guard_to_del) { /* The number of guard timer count is more than the guard timer to delete */ while (start_index < no_of_guard_to_del) { /* Copy the previous stored timer values to the present */ ps_timer_info->guard_to_value[start_index] = (uint16_t) (ps_timer_info->guard_to_value[ (no_of_guard_to_del + start_index)]); ps_timer_info->iframe_send_count[start_index] = (uint8_t) (ps_timer_info->iframe_send_count[ (no_of_guard_to_del + start_index)]); PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX DELETED : 0x%02X\n", ps_timer_info->timer_ns_value[start_index]); ps_timer_info->timer_ns_value[start_index] = (uint8_t) (ps_timer_info->timer_ns_value[ (no_of_guard_to_del + start_index)]); ps_timer_info->frame_type[start_index] = (uint8_t) (ps_timer_info->frame_type[ (no_of_guard_to_del + start_index)]); start_index = (uint8_t)(start_index + 1); } } else { while (start_index < no_of_guard_to_del) { ps_timer_info->guard_to_value[start_index] = 0; ps_timer_info->iframe_send_count[start_index] = 0; PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX DELETED ELSE : 0x%02X\n", ps_timer_info->timer_ns_value[start_index]); ps_timer_info->timer_ns_value[start_index] = 0; ps_timer_info->frame_type[start_index] = 0; start_index = (uint8_t)(start_index + 1); } } if (timer_count >= no_of_guard_to_del) { timer_count = (uint8_t)(timer_count - no_of_guard_to_del); } else { if (0 != no_of_guard_to_del) { timer_count = 0; } } timerid = ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER]; ps_timer_info->guard_to_count = timer_count; PH_LLCNFC_DEBUG("GUARD TIMER COUNT AFTER DELETE: 0x%02X\n", timer_count); if (0 == ps_timer_info->guard_to_count) { /* This means that there are no frames to run guard timer, so set the timer flag to 0 */ ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT, PH_LLCNFC_TO_NOOFBITS, 0); } else { timerflag = 0; } break; } #ifdef PIGGY_BACK case PH_LLCNFC_ACKTIMER: { ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT, PH_LLCNFC_TO_NOOFBITS, 0); timerid = ps_timer_info->timer_id[PH_LLCNFC_ACKTIMER]; break; } #endif /* #ifdef PIGGY_BACK */ default: { result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_PARAMETER); break; } } if ((NFCSTATUS_SUCCESS == result) && (timerflag > 0)) { PH_LLCNFC_DEBUG("OSAL STOP TIMER CALLED TIMER ID : 0x%02X\n", timerid); phOsalNfc_Timer_Stop (timerid); } PH_LLCNFC_PRINT("\n\nLLC : STOP TIMER END\n\n"); #else /* #ifdef LLC_TIMER_ENABLE */ PHNFC_UNUSED_VARIABLE (result); PHNFC_UNUSED_VARIABLE (TimerType); PHNFC_UNUSED_VARIABLE (no_of_gaurd_to_del); #endif /* #ifdef LLC_TIMER_ENABLE */ }
void phLlcNfc_StopAllTimers (void) { #ifdef LLC_TIMER_ENABLE phLlcNfc_Timerinfo_t *ps_timer_info = NULL; uint8_t timer_started = 0; uint32_t timerid = 0; uint8_t timer_index = 0; ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo); PH_LLCNFC_PRINT("\n\nLLC : STOP ALL TIMERS CALLED \n\n"); timerid = ps_timer_info->timer_id[timer_index]; timer_started = (uint8_t) GET_BITS8(ps_timer_info->timer_flag, PH_LLCNFC_CON_TO_BIT, PH_LLCNFC_TO_NOOFBITS); PH_LLCNFC_DEBUG("CONNECTION TIMER ID: 0x%02X\n", timerid); if (0 != timer_started) { /* Connection timer is started, so now stop it */ ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_CON_TO_BIT, PH_LLCNFC_TO_NOOFBITS, 0); #if 0 ps_timer_info->con_to_value = 0; #endif /* #if 0 */ phOsalNfc_Timer_Stop (timerid); } timer_index = (uint8_t)(timer_index + 1); timerid = ps_timer_info->timer_id[timer_index]; timer_started = (uint8_t)GET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT, PH_LLCNFC_TO_NOOFBITS); if (0 != timer_started) { /* Guard timer is already started */ ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT, PH_LLCNFC_TO_NOOFBITS, 0); timer_index = 0; ps_timer_info->guard_to_count = 0; #if 0 /* Reset all the guard timer related variables */ while (timer_index < ps_timer_info->guard_to_count) { ps_timer_info->guard_to_value[timer_index] = 0; ps_timer_info->iframe_send_count[timer_index] = 0; timer_index = (uint8_t)(timer_index + 1); } #endif /* #if 0 */ PH_LLCNFC_DEBUG("GUARD TIMER ID: 0x%02X\n", timerid); /* Stop the timer */ phOsalNfc_Timer_Stop (timerid); PH_LLCNFC_PRINT("\n\nLLC : STOP ALL TIMERS END \n\n"); } #endif /* #ifdef LLC_TIMER_ENABLE */ }
NFCSTATUS phLlcNfc_StartTimers ( uint8_t TimerType, uint8_t ns_value ) { NFCSTATUS result = NFCSTATUS_SUCCESS; #ifdef LLC_TIMER_ENABLE uint32_t timerid = 0; uint8_t timerstarted = 0; uint8_t timer_count = 0; uint16_t timer_resolution = 0; ppCallBck_t Callback = NULL; phLlcNfc_Timerinfo_t *ps_timer_info = NULL; ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo); PHNFC_UNUSED_VARIABLE(result); PH_LLCNFC_PRINT("\n\nLLC : START TIMER CALLED\n\n"); /* Depending on the timer type, use the Osal callback */ switch(TimerType) { case PH_LLCNFC_CONNECTIONTIMER: { /* Get the connection timer flag */ timerstarted = (uint8_t) GET_BITS8(ps_timer_info->timer_flag, PH_LLCNFC_CON_TO_BIT, PH_LLCNFC_TO_NOOFBITS); if (0 == timerstarted) { /* Timer not started, so start the timer */ gpphLlcNfc_Ctxt->s_timerinfo.timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_CON_TO_BIT, PH_LLCNFC_TO_NOOFBITS, (PH_LLCNFC_CON_TO_BIT + 1)); } timerid = ps_timer_info->timer_id[PH_LLCNFC_CONNECTION_TO_INDEX]; Callback = (ppCallBck_t)&phLlcNfc_ConnectionTimeoutCb; timer_resolution = ps_timer_info->con_to_value = (uint16_t) PH_LLCNFC_CONNECTION_TO_VALUE; break; } case PH_LLCNFC_GUARDTIMER: { if (ps_timer_info->guard_to_count < PH_LLCNFC_MAX_GUARD_TIMER) { timer_count = ps_timer_info->guard_to_count; timer_resolution = (uint16_t)PH_LLCNFC_RESOLUTION; PH_LLCNFC_DEBUG("RESOLUTION VALUE : 0x%02X\n", PH_LLCNFC_RESOLUTION); PH_LLCNFC_DEBUG("TIME-OUT VALUE : 0x%02X\n", PH_LLCNFC_GUARD_TO_VALUE); /* Get the guard timer flag */ timerstarted = (uint8_t) GET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT, PH_LLCNFC_TO_NOOFBITS); PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX : 0x%02X\n", ns_value); PH_LLCNFC_DEBUG("GUARD TIMER COUNT : 0x%02X\n", timer_count); PH_LLCNFC_DEBUG("GUARD TIMER STARTED : 0x%02X\n", timerstarted); if (0 == timerstarted) { /* Timer not started, so start the timer */ ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT, PH_LLCNFC_TO_NOOFBITS, PH_LLCNFC_GUARD_TO_BIT); } timerid = ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER]; Callback = (ppCallBck_t)&phLlcNfc_GuardTimeoutCb; /* Guard time out value */ ps_timer_info->guard_to_value[timer_count] = (uint16_t) PH_LLCNFC_GUARD_TO_VALUE; ps_timer_info->timer_ns_value[timer_count] = ns_value; ps_timer_info->frame_type[timer_count] = (uint8_t)invalid_frame; ps_timer_info->iframe_send_count[timer_count] = 0; if ((timer_count > 0) && (ps_timer_info->guard_to_value[(timer_count - 1)] >= PH_LLCNFC_GUARD_TO_VALUE)) { /* If the timer has been started already and the value is same as the previous means that timer has still not expired, so the time out value is increased by a resolution */ ps_timer_info->guard_to_value[timer_count] = (uint16_t) (ps_timer_info->guard_to_value[(timer_count - 1)] + PH_LLCNFC_RESOLUTION); } PH_LLCNFC_DEBUG("GUARD TIMER VALUE : 0x%04X\n", ps_timer_info->guard_to_value[timer_count]); ps_timer_info->guard_to_count = (uint8_t)( ps_timer_info->guard_to_count + 1); } else { /* TIMER should not start, because the time out count has readched the limit */ timerstarted = TRUE; } break; } #ifdef PIGGY_BACK case PH_LLCNFC_ACKTIMER: { /* Get the ack timer flag */ timerstarted = (uint8_t)GET_BITS8 ( ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT, PH_LLCNFC_TO_NOOFBITS); if (0 == timerstarted) { /* Timer not started, so start the timer */ ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, PH_LLCNFC_GUARD_TO_BIT PH_LLCNFC_TO_NOOFBITS (PH_LLCNFC_GUARD_TO_BIT - 1)); } timerid = ps_timer_info->timer_id[PH_LLCNFC_ACKTIMER]; Callback = (ppCallBck_t)&phLlcNfc_AckTimeoutCb; break; } #endif /* #ifdef PIGGY_BACK */ default: { result = PHNFCSTVAL(CID_NFC_LLC, NFCSTATUS_INVALID_PARAMETER); break; } } if ((NFCSTATUS_SUCCESS == result) && (FALSE == timerstarted)) { PH_LLCNFC_DEBUG("OSAL START TIMER CALLED TIMER ID : 0x%02X\n", timerid); phOsalNfc_Timer_Start (timerid, timer_resolution, Callback, NULL); } PH_LLCNFC_PRINT("\n\nLLC : START TIMER END\n\n"); #else /* #ifdef LLC_TIMER_ENABLE */ PHNFC_UNUSED_VARIABLE(result); PHNFC_UNUSED_VARIABLE(TimerType); PHNFC_UNUSED_VARIABLE(ns_value); #endif /* #ifdef LLC_TIMER_ENABLE */ return result; }