diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7.c b/nfapi/open-nFAPI/pnf/src/pnf_p7.c index 19e14c0607..f10d37820c 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf_p7.c +++ b/nfapi/open-nFAPI/pnf/src/pnf_p7.c @@ -1309,86 +1309,21 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf) return 0; } - - -// return 1 if in window -// return 0 if out of window - -uint8_t is_nr_p7_request_in_window(uint16_t sfn,uint16_t slot, const char* name, pnf_p7_t* phy) +bool is_nr_p7_request_in_window(const uint16_t sfn, const uint16_t slot, const char* name, const pnf_p7_t* phy) { - uint32_t recv_sfn_slot_dec = NFAPI_SFNSLOT2DEC(sfn,slot); - uint32_t current_sfn_slot_dec = NFAPI_SFNSLOT2DEC(phy->sfn,phy->slot); - //printf("p7_msg_sfn: %d, p7_msg_slot: %d, phy_sfn:%d , phy_slot:%d \n",sfn,slot,phy->sfn,phy->slot); - uint8_t in_window = 0; - uint8_t timing_window = phy->_public.slot_buffer_size; - - // if(recv_sfn_slot_dec <= current_sfn_slot_dec) - // { - // // Need to check for wrap in window - // if(((recv_sfn_slot_dec + timing_window) % NFAPI_MAX_SFNSLOTDEC) < recv_sfn_slot_dec) - // { - // if(current_sfn_slot_dec > ((recv_sfn_slot_dec + timing_window) % NFAPI_MAX_SFNSLOTDEC)) - // { - // // out of window - // NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is late %d (with wrap)\n", current_sfn_slot_dec, name, recv_sfn_slot_dec); - // } - // else - // { - // // ok - // //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d (with wrap)\n", current_sfn_sf_dec, name, recv_sfn_sf_dec); - // in_window = 1; - // } - // } - // else - // { - // if((current_sfn_slot_dec - recv_sfn_slot_dec) <= timing_window) - // { - // // in window - // //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_slot_dec, name, recv_sfn_slot_dec); - // in_window = 1; - // } - // //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in late %d (delta:%d)\n", current_sfn_slot_dec, name, recv_sfn_slot_dec, (current_sfn_slot_dec - recv_sfn_slot_dec)); - // } - - // } - // else - // { - // // Need to check it is in window - // if((recv_sfn_slot_dec - current_sfn_slot_dec) <= timing_window) - // { - // // in window - // //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_sf_dec, name, recv_sfn_sf_dec); - // in_window = 1; - // } - // else - // { - // // too far in the future - // NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", current_sfn_slot_dec, name, recv_sfn_slot_dec, (recv_sfn_slot_dec - current_sfn_slot_dec), timing_window); - // } - - // } - if(current_sfn_slot_dec <= recv_sfn_slot_dec + timing_window){ - in_window = 1; - //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_slot_dec, name, recv_sfn_slot_dec); - } - else if(current_sfn_slot_dec + NFAPI_MAX_SFNSLOTDEC <= recv_sfn_slot_dec + timing_window){ //checking for wrap - in_window = 1; - //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_slot_dec, name, recv_sfn_slot_dec); - } - - else - { - - NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", current_sfn_slot_dec, name, recv_sfn_slot_dec, (current_sfn_slot_dec - recv_sfn_slot_dec), timing_window); - - }//Need to add more cases - - - return in_window; + const uint32_t recv = NFAPI_SFNSLOT2DEC(sfn, slot); // unpack sfn/slot + const uint32_t curr = NFAPI_SFNSLOT2DEC(phy->sfn, phy->slot); + const uint8_t timing_window = phy->_public.slot_buffer_size; + uint32_t diff = curr < recv ? recv - curr : curr - recv; + if (diff > NFAPI_MAX_SFNSLOTDEC / 2) + diff = NFAPI_MAX_SFNSLOTDEC - diff; + if (diff > timing_window) { + NFAPI_TRACE(NFAPI_TRACE_WARN, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", curr, name, recv, diff, timing_window); + return false; + } + return true; } - - uint8_t is_p7_request_in_window(uint16_t sfnsf, const char* name, pnf_p7_t* phy) { uint32_t recv_sfn_sf_dec = NFAPI_SFNSF2DEC(sfnsf);