This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: CC2640R2F

Part Number: CC2640R2F

Tool/software:

Hello,

I m using code composer studio version 10.3.0.00007

ble sdk simplelink_cc2640r2_sdk_5_10_00_02

XDC tool version 3_51_03_28_core

external flash w25x40cluxig

predefined symbol MAX_NUM_BLE_CONNS=1 

In  ll_config.h,  #define MAX_NUM_BLE_CONNS    3 

This is my part of code to identified the destination 

//find address of coin to connect in list of scanned coins
uint8 find_dest_addr() //// ** This function finds destination address for the shortest distance Coin or gateway **//
{
uint8_t scenario=0,diff=0; //
uint8_t i;
uint16_t dest_id=0xFFFF;
uint8_t dest_id_index;
uint8_t devices_in_range=0,devices_out_range=0;
int8 highest_RSSI = -96;
int8 lowest_RSSI = -60;


for (i=0;i<dev_list_index;i++)
{
if (scanned_coin_info[i].in_range == TRUE)
devices_in_range++;
else
devices_out_range++;
}


if (devices_out_range==0 && devices_in_range != 0 )
scenario = 1;
else if (devices_out_range!=0 && devices_in_range == 0 )
scenario = 2;
else if (devices_out_range!=0 && devices_in_range != 0)
scenario = 3;
else
scenario = 0xFF;


if(gatdata==0) //coin to gateway
{
if (scenario!=0xFF)
{
if(scenario==1 || scenario==3)
{
for (i=0;i<dev_list_index;i++)
{
if((scanned_coin_info[i].in_range == TRUE) && (scanned_coin_info[i].RSSI < lowest_RSSI) &&(scanned_coin_info[i].static_id< dest_id))
{
dest_id_index = i;
lowest_RSSI=scanned_coin_info[i].RSSI;

}
}

}
else if (scenario == 2)
{
for (i=0;i<dev_list_index;i++)
{
if((scanned_coin_info[i].in_range == FALSE) && (scanned_coin_info[i].RSSI > highest_RSSI))
{
dest_id_index = i;
highest_RSSI=scanned_coin_info[i].RSSI;
}
}
}
return dest_id_index;

}
}


else if(gatdata==1) //gateway to coin
{
dest_id=0x0000;
if (scenario!=0xFF)
{
if(scenario==1 || scenario==3)
{
if(same_dyn_id==1)
{
for (i=0;i<dev_list_index;i++)
{
if((scanned_coin_info[i].in_range == TRUE) && (scanned_coin_info[i].RSSI < lowest_RSSI) && (scanned_coin_info[i].static_id > dest_id))
{
dest_id_index = i;
lowest_RSSI=scanned_coin_info[i].RSSI;
}
}
}
else if(same_dyn_id==0)
{
for (i=0;i<dev_list_index;i++)
{
if((scanned_coin_info[i].in_range == TRUE) && (scanned_coin_info[i].dyn_id_16 > dest_id))
{
dest_id_index = i;
dest_id=scanned_coin_info[i].dyn_id_16;
}
}
}
}
else if (scenario == 2)
{
for (i=0;i<dev_list_index;i++)
{
if((scanned_coin_info[i].in_range == FALSE) && (scanned_coin_info[i].RSSI > highest_RSSI))
{
dest_id_index = i;
highest_RSSI=scanned_coin_info[i].RSSI;
}
}
}

}

return dest_id_index;
}
else
return 0xFF;
}

I want to implement simultaneous connections.please guide me.

Thanks

  • Hello,

    Thanks for reaching out.

    May I ask if you are using an example from the SDK as a reference to build your application on top? Do you want to establish a connection or would it be enough to read the RSSI from the advertisement report when scanning? Could you please try setting the MAX_NUM_BLE_CONNS value inside the project properties -> Build -> Arm Compuler -> Predefined Symbols.

    BR,

    David.

  • hello,

    I have custom board and accordingly I have working code with establishing one connection at a time depending upon the rssi as i mentioned in the code  above.i will try according to your suggestion about MAX_NUM_BLE_CONNS .But is there any documents which i can use to implement this.

    thanks

  • Hello,

    Let me know how it goes with modifying the predefined value of the parameter. You can start with the simple_peripheral example from the SDK and also take a look at our Users Guide documentation here.

    BR,

    David.

  • hello,

    In ble sdk simplelink_cc2640r2_sdk_5_10_00_02 how many simultaneous connections it allowed. Accordingly i can assign value to MAX_NUM_BLE_CONNS 

    Thanks

  • Hello,

    CC2640R2 should be able to support up to 8 simultaneous connection. However, the limitation at the end has to do mostly with the available RAM. This is due to the fact that each connection requires a certain amount of heap to be maintained and allocated.

    BR,

    David.

  • hello, 

    I tried with  setting the MAX_NUM_BLE_CONNS value inside the project properties -> Build -> Arm Compiler -> Predefined Symbols. previously it was 1 i changed with 3.but my program is stuck ,it is not going inside the initialization function.so please guide me 

  • Hello,

    i have done some changes to achieve simultaneous connection 
    MAX_NUM_BLE_CONNS 3

    1.present code

    typedef struct
    {
    uint16_t connHandle; // connection handle of an active connection
    uint8_t strAddr[B_STR_ADDR_LEN]; // memory location for menu module to store address string
    } connHandleMapEntry_t;

    1.the changes i have done in my code to achieve simultaneous connection

    typedef struct
    {
    uint16_t connHandle; // connection handle of an active connection
    uint8_t strAddr[B_STR_ADDR_LEN]; // memory location for menu module to store address string
    uint8_t discState;
    } connHandleMapEntry_t;

    2.present code

    // pointer to allocate the connection handle map
    static connHandleMapEntry_t *connHandleMap;

    2.the changes i have done in my code to achieve simultaneous connection

    // pointer to allocate the connection handle map
    static connHandleMapEntry_t *connHandleMap[MAX_NUM_BLE_CONNS];

    3.present code

    void disconnect_and_update_buffer(uint8 );
    void disconnect_and_update_gateway_buffer(uint8 );

    3.the changes i have done in my code to achieve simultaneous connection

    void disconnect_and_update_buffer(uint8 next_index, uint16_t chandle);
    void disconnect_and_update_gateway_buffer(uint8 next_index1, uint16_t chandle);

    4.present code in initialization

    if (connHandleMap = ICall_malloc(sizeof(connHandleMapEntry_t) * maxNumBleConns))
    {
    // Init index to connection handle map
    for (uint8_t i = 0; i < maxNumBleConns; i++)
    {
    connHandleMap[i].connHandle = INVALID_CONNHANDLE;
    }
    }

    4.the changes i have done in my code to achieve simultaneous connection

    // if (connHandleMap[i] = ICall_malloc(sizeof(connHandleMapEntry_t) * maxNumBleConns))
    // {
    // Init index to connection handle map
    for (uint8_t i = 0; i < maxNumBleConns; i++)
    {
    connHandleMap[i] = (connHandleMapEntry_t *) ICall_malloc(sizeof(connHandleMapEntry_t));
    if (connHandleMap[i] != NULL)
    {
    connHandleMap[i]->connHandle = INVALID_CONNHANDLE;
    connHandleMap[i]->discState = BLE_DISC_STATE_IDLE;
    // Initialize other members as needed
    }
    else {
    // Handle allocation error:
    // You might want to log an error, or take appropriate action
    // to prevent further issues. For example:
    //System_abort("Memory allocation error in multi_role_init");
    }
    }
    // }

    5.present code
    //ack loop
    if (events & ACK_TIMEOUT_EVT) // this is acknowledgement clock starts when data sent and stops once acknowledgment is receied for the data sent
    {
    one_sec_count++;
    if (one_sec_count>=60)
    {
    one_min_count++;
    one_sec_count=0;
    }
    // if (one_min_count>=70)
    // one_min_count=0;

    if (status_resend==1 && one_sec_count>=30)
    {
    status_resend=0;
    funct_set_status_msg();
    /*dummy_sensor_data[0]=sensor_id[0];
    dummy_sensor_data[1]=sensor_id[1];
    dummy_sensor_data[2]=0x11;
    dummy_sensor_data[3]=222;
    dummy_sensor_data[4]=0;
    dummy_sensor_data[5]=0;

    memcpy(dataToSend[1],dummy_sensor_data,SENSOR_LEN);
    memset(dummy_sensor_data,0,sizeof(dummy_sensor_data));*/
    one_sec_count=0;
    //count=0;
    add_to_buffer(1);
    }
    if(gatdata==0) // For mormal data transfer it enters here
    {
    disconnect_and_update_buffer(ack_packet[1]);
    dev_disconnect_central=1;
    }
    else if(gatdata==1) // for reverse communication it enters here
    {
    disconnect_and_update_gateway_buffer(ack_packet[1]);
    }
    }

    5.the changes i have done in my code to achieve simultaneous connection

    //ack loop
    if (events & ACK_TIMEOUT_EVT) // this is acknowledgement clock starts when data sent and stops once acknowledgment is receied for the data sent
    {
    one_sec_count++;
    if (one_sec_count>=60)
    {
    one_min_count++;
    one_sec_count=0;
    }
    // if (one_min_count>=70)
    // one_min_count=0;

    if (status_resend==1 && one_sec_count>=30)
    {
    status_resend=0;
    funct_set_status_msg();
    /*dummy_sensor_data[0]=sensor_id[0];
    dummy_sensor_data[1]=sensor_id[1];
    dummy_sensor_data[2]=0x11;
    dummy_sensor_data[3]=222;
    dummy_sensor_data[4]=0;
    dummy_sensor_data[5]=0;

    memcpy(dataToSend[1],dummy_sensor_data,SENSOR_LEN);
    memset(dummy_sensor_data,0,sizeof(dummy_sensor_data));*/
    one_sec_count=0;
    //count=0;
    add_to_buffer(1);
    }
    if(gatdata==0) // For mormal data transfer it enters here
    {
    // Retrieve the connection handle
    uint16_t chandle = connHandleMap[cindex]->connHandle; //assuming cindex is set before this, and connHandleMap is using uint8_t

    disconnect_and_update_buffer(ack_packet[1], chandle); // Pass the connection handle
    dev_disconnect_central = 1;
    }
    else if(gatdata==1) // for reverse communication it enters here
    {
    // Retrieve the connection handle
    uint16_t chandle = connHandleMap[cindex]->connHandle; //assuming cindex is set before this, and connHandleMap is using uint8_t

    disconnect_and_update_gateway_buffer(ack_packet[1], chandle);
    }
    }

    6.present code

    void DataSend(uint8* dataToSend,uint8 size,uint8_t chandle) // This functioninvolved in data send from BLE to BLE **//
    {
    attPrepareWriteReq_t req;
    req.pValue = GATT_bm_alloc(connHandleMap[cindex].connHandle, ATT_WRITE_REQ, size, NULL);

    if ( req.pValue != NULL )
    {
    req.handle = chandle;

    req.offset = 0;

    req.len = size;

    memcpy(req.pValue, dataToSend,size);
    status = GATT_WriteLongCharValue(connHandleMap[cindex].connHandle, &req, selfEntity);

    if ( status != SUCCESS )
    GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
    }
    }

    6.the changes i have done in my code to achieve simultaneous connection

    //data transfer fn
    void DataSend(uint8_t* dataToSend, uint8_t size, uint8_t chandle) // Changed chandle type to uint8_t
    {
    attPrepareWriteReq_t req;

    // Find the connection index based on the chandle
    int cindex = -1; // Initialize to an invalid value
    for (int i = 0; i < MAX_NUM_BLE_CONNS; i++)
    {
    if (connHandleMap[i]->connHandle == chandle)
    {
    cindex = i;
    break;
    }
    }

    if (cindex == -1)
    {
    // Connection handle not found, handle error
    return; // Or log an error, etc.
    }

    req.pValue = GATT_bm_alloc(chandle, ATT_WRITE_REQ, size, NULL); // Use chandle

    if (req.pValue != NULL)
    {
    req.handle = chandle;

    req.offset = 0;

    req.len = size;

    memcpy(req.pValue, dataToSend, size);
    status = GATT_WriteLongCharValue(chandle, &req, selfEntity); // Use chandle

    if (status != SUCCESS)
    GATT_bm_free((gattMsg_t*)&req, ATT_WRITE_REQ);
    }
    }

    7.present code

    static void multi_role_processRoleEvent(gapMultiRoleEvent_t *pEvent)
    {
    switch (pEvent->gap.opcode)
    {
    // GAPRole started
    case GAP_DEVICE_INIT_DONE_EVENT:
    {
    uint8_t advHandle = 0;
    HCI_LE_SetPhyCmd(advHandle, LL_PHY_CODED, LL_PHY_CODED);
    }
    break;

    // Advertising started
    case GAP_MAKE_DISCOVERABLE_DONE_EVENT: // When advertisement starts it enters this case **//
    {

    }
    break;

    // Advertising ended
    case GAP_END_DISCOVERABLE_DONE_EVENT: // When advertisement stops it enters this case **//
    {

    }
    break;

    // A discovered device report
    case GAP_DEVICE_INFO_EVENT: // When scanning is on it enters this case with scanned results and checks for valid device **//
    {
    //adv data copy and compare in prcoess adv packet fn
    memset(device_name,0,sizeof(device_name));
    memcpy(adv_data,pEvent->deviceInfo.pEvtData,pEvent->deviceInfo.dataLen);

    ptr=&adv_data[2];
    memcpy(device_name,ptr,device_length);

    memcpy(curr_addr,pEvent->deviceInfo.addr,GATEWAY_DATA);
    devices_discovered++;

    if (devices_discovered!=1)
    {
    res=compare_string(curr_addr,prev_addr,GATEWAY_DATA);
    if (res==0)
    {
    memcpy(prev_addr,curr_addr,GATEWAY_DATA);
    dev_counter++;

    if(pEvent->deviceInfo.eventType==GAP_ADRPT_SCAN_RSP)
    {
    if(compare_string(device_name,gateway_name,device_length)==1) // this validates the Gateway **//
    RSSI=pEvent->deviceInfo.rssi;
    else if(compare_string(device_name,moving_device_name,moving_device_length)==1) //// This validates the coin **//
    RSSI=pEvent->deviceInfo.rssi;

    process_adv_packet();
    }
    }
    else if(res==1 && pEvent->deviceInfo.eventType==GAP_ADRPT_SCAN_RSP)
    {
    if(compare_string(device_name,gateway_name,device_length)==1) // this validates the Gateway **//
    RSSI=pEvent->deviceInfo.rssi;

    else if(compare_string(device_name,moving_device_name,moving_device_length)==1) // This validates the coin **//
    RSSI=pEvent->deviceInfo.rssi;


    process_adv_packet();
    }
    }
    else
    {
    memcpy(prev_addr,curr_addr,GATEWAY_DATA);
    dev_counter++;
    }
    }
    break;

    // End of discovery report
    case GAP_DEVICE_DISCOVERY_EVENT: // ** Once the Scan interval is reached the count it enters in this case **//
    {
    uint8 dev_index;
    // Discovery complete
    scanningStarted = FALSE; // ** scanning is turned false **//
    scan_count++;

    if(scan_count==250)
    {
    scan_count=26;
    // if (no_of_scan_cycle<10)
    // no_of_scan_cycle++;
    }

    //rest dyn id if 25 scans
    if(scan_count>=25 && dyn_scan_start==0 && gatdata==0 )
    {
    dyn_scan_start=1;

    scan_count=0;
    range=3;
    //dynamic_id_16=0x0064;
    //dynamic_id[0]=0x00;
    //dynamic_id[1]=0x64;

    //Util_stopClock(&dyn_id_resend_clock);
    //Util_rescheduleClock(&dyn_id_resend_clock,DYN_ID_RESEND_PERIOD);
    //dynamic_resend=0;

    turn_on_adv();

    coin_adv();
    }

    /*if(same_device_transfer==2 && gatdata==0)
    {
    if((abs(dyn_id_previous_16-dynamic_id_16)>1) && (abs(dyn_id_previous_16-dynamic_id_16)!=0x0064))
    {
    same_device_transfer=0;
    dynamic_id_16=dyn_id_previous_16+1;
    // dynamic_id[0]=0x00;//(dynamic_id_16 & 0xFF00) >> 8;
    dynamic_id[1]=(dynamic_id_16 & 0x00FF);

    dynamic_data[0]=sensor_id[0];
    dynamic_data[1]=sensor_id[1];
    dynamic_data[2]=0x16;
    dynamic_data[3]=0x00;
    dynamic_data[4]=dynamic_id[1];
    dynamic_data[5]=0;
    if (last_dynamic_id != dynamic_id[1])
    {
    last_dynamic_id=dynamic_id[1];
    memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    add_to_buffer(5);
    }

    // memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    memset(dynamic_data,0,sizeof(dynamic_data));

    // add_to_buffer(5);

    coin_adv();

    Util_startClock(&dyn_id_resend_clock);
    }
    else if(abs(dyn_id_previous_16-dynamic_id_16)==1)
    {
    same_device_transfer=0;
    memset(same_dev_address,0,sizeof(same_dev_address));
    dyn_id_previous_16=0;
    }
    }*/

    if(buffer_counter2!=0 && gatdata==1) //check this condition when gateway is off
    turn_on_adv();

    // Copy all of the results
    scanRes = pEvent->discCmpl.numDevs;
    memcpy(devList, pEvent->discCmpl.pDevList, (sizeof(gapDevRec_t) * scanRes));

    //connection forming loop
    if (dev_list_index>0)
    {
    dest_index=find_dest_addr();

    if(dest_index!=0xFF && dyn_scan_start==0)
    {
    dev_index=scanned_coin_info[dest_index].DevList_index; // This finds the MAC Id for the shortest path coin or gateway **//
    memcpy(dest_addr,devList[dev_index].addr,GATEWAY_DATA); // ** MAC ID is coped in destination address **//
    addrType1=devList[dev_index].addrType;

    /* if(same_device_transfer==0)
    dyn_id_previous_16=scanned_coin_info[dest_index].dyn_id_16;*/

    //initialize scan index to last device
    GAPRole_EstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE,DEFAULT_LINK_WHITE_LIST,addrType1,dest_addr); //// ** connection is established using this command **//

    // Set PHY to Coded for connection
    uint8_t advHandle = 0;
    HCI_LE_SetPhyCmd(advHandle, LL_PHY_CODED, LL_PHY_CODED);
    //HCI_LE_SetPhyCmd(pEvent->linkCmpl.connectionHandle, LL_PHY_CODED, LL_PHY_CODED, 0);
    }
    else if(dyn_scan_start==1 )//&& dynamic_id_16!=0x0064) // DYNAMIC ID CHANGED,FOUND COIN OR GATEWAY THEN IT START ADVERTISE
    {
    dyn_scan_start=0;
    dev_list_index=0;
    scan_count=0;

    turn_on_adv();

    coin_adv();

    memset(scanned_coin_info,0,sizeof(scanned_coin_info));
    /* memset(scanned_dyn_id,0,sizeof(scanned_dyn_id));

    dynamic_data[0]=sensor_id[0];
    dynamic_data[1]=sensor_id[1];
    dynamic_data[2]=0x16;
    dynamic_data[3]=0x00;
    dynamic_data[4]=dynamic_id[1];
    dynamic_data[5]=0;
    if (last_dynamic_id != dynamic_id[1])
    {
    last_dynamic_id=dynamic_id[1];
    memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    add_to_buffer(5);
    }
    // memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    memset(dynamic_data,0,sizeof(dynamic_data));

    // add_to_buffer(5);

    Util_startClock(&dyn_id_resend_clock);*/
    }
    }
    }
    break;

    // Connection has been established
    case GAP_LINK_ESTABLISHED_EVENT:
    {
    // If succesfully established
    if (pEvent->gap.hdr.status == SUCCESS)
    {
    device_connected=1;
    ix=0;jx=0,ig=0;

    PIN_setOutputValue(hGpioPin, Board_GLED, Board_LED_ON);

    // Add index-to-connHandle mapping entry and update menus
    cindex = multi_role_addMappingEntry(pEvent->linkCmpl.connectionHandle, pEvent->linkCmpl.devAddr);

    memcpy(connected_device_address,pEvent->linkCmpl.devAddr,GATEWAY_DATA);

    connRole=pEvent->linkCmpl.connRole;
    // Set PHY options in the HCI command
    HCI_LE_SetPhyCmd(pEvent->linkCmpl.connectionHandle, LL_PHY_CODED, LL_PHY_CODED, 0);

    if (connRole==GAP_PROFILE_PERIPHERAL)
    {
    peripheral_connected=1; //here it is connected from app(mob)

    }
    //if central data transfer start
    if (connRole==GAP_PROFILE_CENTRAL)
    {
    /*if(same_device_transfer==0)
    memcpy(same_dev_address,pEvent->linkCmpl.devAddr,GATEWAY_DATA);

    if(compare_string(connected_device_address,same_dev_address,GATEWAY_DATA)==1)
    same_device_transfer++;
    else if(compare_string(connected_device_address,same_dev_address,GATEWAY_DATA)==0)
    {
    same_device_transfer=0;
    dyn_id_previous_16=0;
    }*/

    //one way coin to gateway
    if (buffer_counter!=0 && gatdata==0)
    {
    read_from_flash(&coin_buffer[0],COIN_DATA); // This function reads data from external flash **//

    if((coin_buffer[0]!=0x00 || coin_buffer[1]!=0x00) && coin_buffer[2]!=0x00)
    {
    ptr=&coin_buffer[0];
    memcpy(packet_to_send,ptr,COIN_DATA);
    DataSend(packet_to_send,COIN_DATA,simple1handle);
    }
    else
    {
    buff_limit_erase();

    if(ext_addr_ch_bt==1)
    ext_addr_ch_bt=2;
    else if(ext_addr_ch_bt==2)
    ext_addr_ch_bt=1;
    write_single_data(ext_addr_ch_bt);

    thresholddata[0]=sensor_id[0];
    thresholddata[1]=sensor_id[1];
    thresholddata[2]=0x45;
    thresholddata[3]=0x4A;
    thresholddata[4]=0x00;
    thresholddata[5]=0x00;
    thresholddata[6]=0x00;
    gatewaydata();
    }

    if (status!=SUCCESS)
    {
    disconnect_and_update_buffer(ix); // ** if sending gets failed
    dev_disconnect_central=1;
    }
    else if (status==SUCCESS)
    {
    Util_startClock(&ack_clock); //if data sent sucessfully i will call this clock
    }
    }
    //reverse direction get data transfer
    else if(buffer_counter2!=0 && gatdata==1)
    {
    ptr=&gateway_buffer[ig][0];
    memcpy(packet_to_send1,ptr,GET_DATA);
    DataSend(packet_to_send1,GET_DATA,simple3handle);
    if (status!=SUCCESS)
    {
    disconnect_and_update_gateway_buffer(ig); // ** if sending gets failed
    }
    else if (status==SUCCESS)
    {
    Util_startClock(&ack_clock); //if data sent sucessfully
    }
    }
    }
    }
    }
    break;

    // Connection has been terminated
    case GAP_LINK_TERMINATED_EVENT:
    {
    //adv on
    turn_on_adv();

    // read current num active so that this doesn't change before this event is processed
    uint8_t currentNumActive = linkDB_NumActive();

    // Find index from connection handle
    connIndex = multi_role_mapConnHandleToIndex(pEvent->linkTerminate.connectionHandle);

    // Cancel the OAD if one is going on
    // A disconnect forces the peer to re-identify
    OAD_cancel(); // this function will notify OAD that device got disconnected **//

    // Check to prevent buffer overrun
    if (connIndex < maxNumBleConns)
    {
    // Clear screen, reset discovery info, and return to main menu
    connHandleMap[connIndex].connHandle = INVALID_CONNHANDLE;

    // Reset discovery info
    discInfo[connIndex].discState = BLE_DISC_STATE_IDLE;
    discInfo[connIndex].charHdl = 0;

    device_connected=0;
    device_connected_inc=0;
    peripheral_connected=0;
    counter_0A=0;
    connection_establish=0;
    // command_0A[0]=0;
    allow_var=0;
    if(dev_disconnect_central==0 && (gatdata==0 && connRole==GAP_PROFILE_CENTRAL))
    {
    disconnect_and_update_buffer(ack_packet[1]);
    }

    dev_disconnect_central=0;

    if(connRole==GAP_PROFILE_PERIPHERAL)
    memset(ack_packet,0,sizeof(ack_packet));

    PIN_setOutputValue(hGpioPin, Board_GLED, Board_LED_OFF);
    connRole=0;
    }
    }
    break;

    // A parameter update has occurred
    case GAP_LINK_PARAM_UPDATE_EVENT:
    {

    }
    break;

    default:
    break;
    }
    }

    7.the changes i have done in my code to achieve simultaneous connection

    static void multi_role_processRoleEvent(gapMultiRoleEvent_t *pEvent)
    {
    uint16_t connHandle;
    switch (pEvent->gap.opcode)
    {
    // GAPRole started
    case GAP_DEVICE_INIT_DONE_EVENT:
    {
    uint8_t advHandle = 0;
    HCI_LE_SetPhyCmd(advHandle, LL_PHY_CODED, LL_PHY_CODED);
    }
    break;

    // Advertising started
    case GAP_MAKE_DISCOVERABLE_DONE_EVENT: // When advertisement starts it enters this case **//
    {

    }
    break;

    // Advertising ended
    case GAP_END_DISCOVERABLE_DONE_EVENT: // When advertisement stops it enters this case **//
    {

    }
    break;

    // A discovered device report
    case GAP_DEVICE_INFO_EVENT: // When scanning is on it enters this case with scanned results and checks for valid device **//
    {
    //adv data copy and compare in prcoess adv packet fn
    memset(device_name,0,sizeof(device_name));
    memcpy(adv_data,pEvent->deviceInfo.pEvtData,pEvent->deviceInfo.dataLen);

    ptr=&adv_data[2];
    memcpy(device_name,ptr,device_length);

    memcpy(curr_addr,pEvent->deviceInfo.addr,GATEWAY_DATA);
    devices_discovered++;

    if (devices_discovered!=1)
    {
    res=compare_string(curr_addr,prev_addr,GATEWAY_DATA);
    if (res==0)
    {
    memcpy(prev_addr,curr_addr,GATEWAY_DATA);
    dev_counter++;

    if(pEvent->deviceInfo.eventType==GAP_ADRPT_SCAN_RSP)
    {
    if(compare_string(device_name,gateway_name,device_length)==1) // this validates the Gateway **//
    RSSI=pEvent->deviceInfo.rssi;
    else if(compare_string(device_name,moving_device_name,moving_device_length)==1) //// This validates the coin **//
    RSSI=pEvent->deviceInfo.rssi;

    process_adv_packet();
    }
    }
    else if(res==1 && pEvent->deviceInfo.eventType==GAP_ADRPT_SCAN_RSP)
    {
    if(compare_string(device_name,gateway_name,device_length)==1) // this validates the Gateway **//
    RSSI=pEvent->deviceInfo.rssi;

    else if(compare_string(device_name,moving_device_name,moving_device_length)==1) // This validates the coin **//
    RSSI=pEvent->deviceInfo.rssi;


    process_adv_packet();
    }
    }
    else
    {
    memcpy(prev_addr,curr_addr,GATEWAY_DATA);
    dev_counter++;
    }
    }
    break;

    // End of discovery report
    case GAP_DEVICE_DISCOVERY_EVENT: // ** Once the Scan interval is reached the count it enters in this case **//
    {
    uint8 dev_index;
    // Discovery complete
    scanningStarted = FALSE; // ** scanning is turned false **//
    scan_count++;

    if(scan_count==250)
    {
    scan_count=26;
    // if (no_of_scan_cycle<10)
    // no_of_scan_cycle++;
    }

    //rest dyn id if 25 scans
    if(scan_count>=25 && dyn_scan_start==0 && gatdata==0 )
    {
    dyn_scan_start=1;

    scan_count=0;
    range=3;
    //dynamic_id_16=0x0064;
    //dynamic_id[0]=0x00;
    //dynamic_id[1]=0x64;

    //Util_stopClock(&dyn_id_resend_clock);
    //Util_rescheduleClock(&dyn_id_resend_clock,DYN_ID_RESEND_PERIOD);
    //dynamic_resend=0;

    turn_on_adv();

    coin_adv();
    }

    /*if(same_device_transfer==2 && gatdata==0)
    {
    if((abs(dyn_id_previous_16-dynamic_id_16)>1) && (abs(dyn_id_previous_16-dynamic_id_16)!=0x0064))
    {
    same_device_transfer=0;
    dynamic_id_16=dyn_id_previous_16+1;
    // dynamic_id[0]=0x00;//(dynamic_id_16 & 0xFF00) >> 8;
    dynamic_id[1]=(dynamic_id_16 & 0x00FF);

    dynamic_data[0]=sensor_id[0];
    dynamic_data[1]=sensor_id[1];
    dynamic_data[2]=0x16;
    dynamic_data[3]=0x00;
    dynamic_data[4]=dynamic_id[1];
    dynamic_data[5]=0;
    if (last_dynamic_id != dynamic_id[1])
    {
    last_dynamic_id=dynamic_id[1];
    memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    add_to_buffer(5);
    }

    // memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    memset(dynamic_data,0,sizeof(dynamic_data));

    // add_to_buffer(5);

    coin_adv();

    Util_startClock(&dyn_id_resend_clock);
    }
    else if(abs(dyn_id_previous_16-dynamic_id_16)==1)
    {
    same_device_transfer=0;
    memset(same_dev_address,0,sizeof(same_dev_address));
    dyn_id_previous_16=0;
    }
    }*/

    if(buffer_counter2!=0 && gatdata==1) //check this condition when gateway is off
    turn_on_adv();

    // Copy all of the results
    scanRes = pEvent->discCmpl.numDevs;
    memcpy(devList, pEvent->discCmpl.pDevList, (sizeof(gapDevRec_t) * scanRes));

    //connection forming loop
    if (dev_list_index>0)
    {
    dest_index=find_dest_addr();

    if(dest_index!=0xFF && dyn_scan_start==0)
    {
    dev_index=scanned_coin_info[dest_index].DevList_index; // This finds the MAC Id for the shortest path coin or gateway **//
    memcpy(dest_addr,devList[dev_index].addr,GATEWAY_DATA); // ** MAC ID is coped in destination address **//
    addrType1=devList[dev_index].addrType;

    /* if(same_device_transfer==0)
    dyn_id_previous_16=scanned_coin_info[dest_index].dyn_id_16;*/

    //initialize scan index to last device
    GAPRole_EstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE,DEFAULT_LINK_WHITE_LIST,addrType1,dest_addr); //// ** connection is established using this command **//

    // Set PHY to Coded for connection
    uint8_t advHandle = 0;
    HCI_LE_SetPhyCmd(advHandle, LL_PHY_CODED, LL_PHY_CODED);
    //HCI_LE_SetPhyCmd(pEvent->linkCmpl.connectionHandle, LL_PHY_CODED, LL_PHY_CODED, 0);
    }
    else if(dyn_scan_start==1 )//&& dynamic_id_16!=0x0064) // DYNAMIC ID CHANGED,FOUND COIN OR GATEWAY THEN IT START ADVERTISE
    {
    dyn_scan_start=0;
    dev_list_index=0;
    scan_count=0;

    turn_on_adv();

    coin_adv();

    memset(scanned_coin_info,0,sizeof(scanned_coin_info));
    /* memset(scanned_dyn_id,0,sizeof(scanned_dyn_id));

    dynamic_data[0]=sensor_id[0];
    dynamic_data[1]=sensor_id[1];
    dynamic_data[2]=0x16;
    dynamic_data[3]=0x00;
    dynamic_data[4]=dynamic_id[1];
    dynamic_data[5]=0;
    if (last_dynamic_id != dynamic_id[1])
    {
    last_dynamic_id=dynamic_id[1];
    memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    add_to_buffer(5);
    }
    // memcpy(dataToSend[5],dynamic_data,SENSOR_LEN);
    memset(dynamic_data,0,sizeof(dynamic_data));

    // add_to_buffer(5);

    Util_startClock(&dyn_id_resend_clock);*/
    }
    }
    }
    break;

    // Connection has been established
    case GAP_LINK_ESTABLISHED_EVENT:
    {
    // If succesfully established
    if (pEvent->gap.hdr.status == SUCCESS)
    {
    device_connected=1;
    ix=0;jx=0,ig=0;

    PIN_setOutputValue(hGpioPin, Board_GLED, Board_LED_ON);

    // Find index from connection handle
    connIndex = multi_role_mapConnHandleToIndex(connHandle);

    if (connIndex != INVALID_CONNHANDLE)
    {
    // Update connection state
    connHandleMap[connIndex]->connHandle = connHandle;
    connHandleMap[connIndex]->discState = BLE_DISC_STATE_IDLE;
    // ... (any other connection setup)
    }

    memcpy(connected_device_address,pEvent->linkCmpl.devAddr,GATEWAY_DATA);

    connRole=pEvent->linkCmpl.connRole;
    // Set PHY options in the HCI command
    HCI_LE_SetPhyCmd(pEvent->linkCmpl.connectionHandle, LL_PHY_CODED, LL_PHY_CODED, 0);

    if (connRole==GAP_PROFILE_PERIPHERAL)
    {
    peripheral_connected=1; //here it is connected from app(mob)

    }
    //if central data transfer start
    if (connRole==GAP_PROFILE_CENTRAL)
    {
    /*if(same_device_transfer==0)
    memcpy(same_dev_address,pEvent->linkCmpl.devAddr,GATEWAY_DATA);

    if(compare_string(connected_device_address,same_dev_address,GATEWAY_DATA)==1)
    same_device_transfer++;
    else if(compare_string(connected_device_address,same_dev_address,GATEWAY_DATA)==0)
    {
    same_device_transfer=0;
    dyn_id_previous_16=0;
    }*/

    //one way coin to gateway
    if (buffer_counter!=0 && gatdata==0)
    {
    read_from_flash(&coin_buffer[0],COIN_DATA); // This function reads data from external flash **//

    if((coin_buffer[0]!=0x00 || coin_buffer[1]!=0x00) && coin_buffer[2]!=0x00)
    {
    ptr=&coin_buffer[0];
    memcpy(packet_to_send,ptr,COIN_DATA);
    DataSend(packet_to_send,COIN_DATA,simple1handle);
    }
    else
    {
    buff_limit_erase();

    if(ext_addr_ch_bt==1)
    ext_addr_ch_bt=2;
    else if(ext_addr_ch_bt==2)
    ext_addr_ch_bt=1;
    write_single_data(ext_addr_ch_bt);

    thresholddata[0]=sensor_id[0];
    thresholddata[1]=sensor_id[1];
    thresholddata[2]=0x45;
    thresholddata[3]=0x4A;
    thresholddata[4]=0x00;
    thresholddata[5]=0x00;
    thresholddata[6]=0x00;
    gatewaydata();
    }

    if (status!=SUCCESS)
    {
    disconnect_and_update_buffer(ix, pEvent->linkCmpl.connectionHandle); // Pass connection handle
    dev_disconnect_central=1;
    }
    else if (status==SUCCESS)
    {
    Util_startClock(&ack_clock); //if data sent sucessfully i will call this clock
    }
    }
    //reverse direction get data transfer
    else if(buffer_counter2!=0 && gatdata==1)
    {
    ptr=&gateway_buffer[ig][0];
    memcpy(packet_to_send1,ptr,GET_DATA);
    DataSend(packet_to_send1,GET_DATA,simple3handle);
    if (status!=SUCCESS)
    {
    disconnect_and_update_gateway_buffer(ig, pEvent->linkCmpl.connectionHandle); // Pass connection handle
    }

    else if (status==SUCCESS)
    {
    Util_startClock(&ack_clock); //if data sent sucessfully
    }
    }
    }
    }
    }
    break;

    // Connection has been terminated
    case GAP_LINK_TERMINATED_EVENT:
    {
    //adv on
    turn_on_adv();

    // read current num active so that this doesn't change before this event is processed
    uint8_t currentNumActive = linkDB_NumActive();
    connHandle = pEvent->linkTerminate.connectionHandle; // Get connection handle

    // Find index from connection handle //check
    connIndex = multi_role_mapConnHandleToIndex(pEvent->linkTerminate.connectionHandle);

    // Cancel the OAD if one is going on
    // A disconnect forces the peer to re-identify
    OAD_cancel(); // this function will notify OAD that device got disconnected **//

    // Check to prevent buffer overrun
    if (connIndex < maxNumBleConns)
    {
    // Clear screen, reset discovery info, and return to main menu
    connHandleMap[connIndex]->connHandle = INVALID_CONNHANDLE;

    // Reset discovery info
    discInfo[connIndex].discState = BLE_DISC_STATE_IDLE;
    discInfo[connIndex].charHdl = 0;

    device_connected=0;
    device_connected_inc=0;
    peripheral_connected=0;
    counter_0A=0;
    connection_establish=0;
    // command_0A[0]=0;
    allow_var=0;
    // Retrieve the connection handle
    uint16_t chandle = pEvent->linkTerminate.connectionHandle;

    if (dev_disconnect_central == 0 && (gatdata == 0 && connRole == GAP_PROFILE_CENTRAL))
    {
    disconnect_and_update_buffer(ack_packet[1], chandle); // Pass the connection handle
    }

    dev_disconnect_central=0;

    if(connRole==GAP_PROFILE_PERIPHERAL)
    memset(ack_packet,0,sizeof(ack_packet));

    PIN_setOutputValue(hGpioPin, Board_GLED, Board_LED_OFF);
    connRole=0;
    }
    }
    break;

    // A parameter update has occurred
    case GAP_LINK_PARAM_UPDATE_EVENT:
    {

    }
    break;

    default:
    break;
    }
    }

    8.present code

    static void multi_role_processCharValueChangeEvt(uint8_t paramID)
    {
    // Print new value depending on which characteristic was updated
    switch(paramID)
    {
    case SIMPLEPROFILE_CHAR1: // This service is Used to send/recei data from BLE to BLE
    device_connected_inc=0;
    //config coin regsiter notify
    if(appflag==1)
    {
    DELAY_MS(500);
    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t), &appdata);
    appflag=0;
    }

    //ack if peripheral
    if(sensor_id_16!=0 && mesh_id!=0 && connRole==GAP_PROFILE_PERIPHERAL) // If device is connected in peripheral mode it starts receiving data here **//
    {
    ack_packet[0]=ack;
    ack_packet[1]=++jx;
    DataSend(ack_packet,ACK_DATA,simple1handle); // here acknowlwdgement is sent when a data r=is received **//

    if(compare_string(simplegattdata,last_coin_packet,COIN_DATA)==0)
    {
    if (status==SUCCESS)
    {
    memcpy(dataToSend[2],simplegattdata,COIN_DATA);
    add_to_buffer(2);
    memcpy(last_coin_packet,simplegattdata,COIN_DATA);
    memset(simplegattdata,0,sizeof(simplegattdata)); // ** the received data from other BLE deviceand is going stored in external flash **//
    }

    status=0xFF;
    }
    }
    //next data transfer if central
    else if (connRole==GAP_PROFILE_CENTRAL && sensor_id_16!=0 && mesh_id!=0) ////"" If the device is connected in central mode it starts sending data here **//
    {
    if (ack_packet[0]==ack && ack_packet[1]<buffer_counter && ack_packet[1]<250) // In a single connection max 250 data can be ssent **//
    {
    first_data_read=0;

    Util_stopClock(&ack_clock);
    read_from_flash(&coin_buffer[0],COIN_DATA);

    ptr=&coin_buffer[0];
    memcpy(packet_to_send,ptr,COIN_DATA);
    DataSend(packet_to_send,COIN_DATA,simple1handle);

    if (status!=SUCCESS)
    {
    disconnect_and_update_buffer(ack_packet[1]);
    dev_disconnect_central=1;
    }
    else
    Util_startClock(&ack_clock);

    status=0xFF;
    }
    else if (ack_packet[0]==ack && ack_packet[1]==buffer_counter)
    {
    first_data_read=0;
    disconnect_and_update_buffer(ack_packet[1]);
    dev_disconnect_central=1;
    }
    }
    break;

    8.the changes i have done in my code to achieve simultaneous connection

    static void multi_role_processCharValueChangeEvt(uint8_t paramID)
    {
    // Print new value depending on which characteristic was updated
    switch(paramID)
    {
    case SIMPLEPROFILE_CHAR1: // This service is Used to send/recei data from BLE to BLE
    device_connected_inc=0;
    //config coin regsiter notify
    if(appflag==1)
    {
    DELAY_MS(500);
    SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t), &appdata);
    appflag=0;
    }

    //ack if peripheral
    if(sensor_id_16!=0 && mesh_id!=0 && connRole==GAP_PROFILE_PERIPHERAL) // If device is connected in peripheral mode it starts receiving data here **//
    {
    ack_packet[0]=ack;
    ack_packet[1]=++jx;
    DataSend(ack_packet,ACK_DATA,simple1handle); // here acknowlwdgement is sent when a data r=is received **//

    if(compare_string(simplegattdata,last_coin_packet,COIN_DATA)==0)
    {
    if (status==SUCCESS)
    {
    memcpy(dataToSend[2],simplegattdata,COIN_DATA);
    add_to_buffer(2);
    memcpy(last_coin_packet,simplegattdata,COIN_DATA);
    memset(simplegattdata,0,sizeof(simplegattdata)); // ** the received data from other BLE deviceand is going stored in external flash **//
    }

    status=0xFF;
    }
    }
    //next data transfer if central
    else if (connRole==GAP_PROFILE_CENTRAL && sensor_id_16!=0 && mesh_id!=0) ////"" If the device is connected in central mode it starts sending data here **//
    {
    if (ack_packet[0]==ack && ack_packet[1]<buffer_counter && ack_packet[1]<250) // In a single connection max 250 data can be ssent **//
    {
    first_data_read=0;

    Util_stopClock(&ack_clock);
    read_from_flash(&coin_buffer[0],COIN_DATA);

    ptr=&coin_buffer[0];
    memcpy(packet_to_send,ptr,COIN_DATA);
    DataSend(packet_to_send,COIN_DATA,simple1handle);

    if (status!=SUCCESS)
    {
    // Retrieve the connection handle using cindex
    uint16_t chandle = connHandleMap[cindex]->connHandle;
    disconnect_and_update_buffer(ack_packet[1], chandle);
    dev_disconnect_central=1;
    }
    else
    Util_startClock(&ack_clock);

    status=0xFF;
    }
    else if (ack_packet[0]==ack && ack_packet[1]==buffer_counter)
    {
    first_data_read=0;
    // Retrieve the connection handle using cindex
    uint16_t chandle = connHandleMap[cindex]->connHandle;
    disconnect_and_update_buffer(ack_packet[1], chandle);
    dev_disconnect_central=1;
    }
    }
    break;

    9.present code

    case SIMPLEPROFILE_CHAR3:
    gatdata=1;

    if (connRole==GAP_PROFILE_CENTRAL && sensor_id_16!=0 && mesh_id!=0)
    {
    if (ack_packet[0]==ack && ack_packet[1]<buffer_counter2)
    {
    Util_stopClock(&ack_clock);
    ptr=&gateway_buffer[ack_packet[1]][0];
    memcpy(packet_to_send1,ptr,GET_DATA);
    DataSend(packet_to_send1,GET_DATA,simple3handle);

    if (status!=SUCCESS)
    disconnect_and_update_gateway_buffer(ack_packet[1]);
    else
    Util_startClock(&ack_clock);

    status=0xFF;
    }
    else if (ack_packet[0]==ack && ack_packet[1]==buffer_counter2)
    disconnect_and_update_gateway_buffer(ack_packet[1]);
    }
    }

    break;

    9.the changes i have done in my code to achieve simultaneous connection

    case SIMPLEPROFILE_CHAR3:
    gatdata=1;

    uint8_t chandle = connHandleMap[cindex]->connHandle;

    if (ack_packet[0] == ack && ack_packet[1] < buffer_counter2)
    {
    Util_stopClock(&ack_clock);
    ptr = &gateway_buffer[ack_packet[1]][0];
    memcpy(packet_to_send1, ptr, GET_DATA);
    DataSend(packet_to_send1, GET_DATA, simple3handle); //Using connection handle

    if (status != SUCCESS)
    disconnect_and_update_gateway_buffer(ack_packet[1], chandle); // Pass connection handle
    else
    Util_startClock(&ack_clock);

    status = 0xFF;
    }
    else if (ack_packet[0] == ack && ack_packet[1] == buffer_counter2)
    disconnect_and_update_gateway_buffer(ack_packet[1], chandle); // Pass connection handle

    }

    10.present code

    static uint16_t multi_role_mapConnHandleToIndex(uint16_t connHandle)
    {
    uint16_t index;
    // Loop through connection
    for (index = 0; index < maxNumBleConns; index ++)
    {
    // If matching connection handle found
    if (connHandleMap[index].connHandle == connHandle)
    {
    return index;
    }
    }
    // Not found if we got here
    return INVALID_CONNHANDLE;
    }

    10.the changes i have done in my code to achieve simultaneous connection

    static uint16_t multi_role_mapConnHandleToIndex(uint16_t connHandle)
    {
    uint16_t index;
    // Loop through connection
    for (index = 0; index < maxNumBleConns; index ++)
    {
    // If matching connection handle found
    if (connHandleMap[index]->connHandle == connHandle)
    {
    return index;
    }
    }
    // Not found if we got here
    return INVALID_CONNHANDLE;
    }

    11.present code

    static uint8_t multi_role_addMappingEntry(uint16_t connHandle, uint8_t *addr)
    {
    uint16_t index;
    // Loop though connections
    for (index = 0; index < maxNumBleConns; index++)
    {
    // If there is an open connection
    if (connHandleMap[index].connHandle == INVALID_CONNHANDLE)
    {
    // Store mapping
    connHandleMap[index].connHandle = connHandle;

    // Convert address to string
    uint8_t *pAddr = (uint8_t *) Util_convertBdAddr2Str(addr);

    // Copy converted string to persistent connection handle list
    memcpy(connHandleMap[index].strAddr, pAddr, B_STR_ADDR_LEN);

    return index;
    }
    }
    // No room if we get here
    return bleNoResources;
    }

    11.the changes i have done in my code to achieve simultaneous connection

    static uint8_t multi_role_addMappingEntry(uint16_t connHandle, uint8_t *addr)
    {
    uint16_t index;
    // Loop though connections
    for (index = 0; index < maxNumBleConns; index++)
    {
    // If there is an open connection
    if (connHandleMap[index]->connHandle == INVALID_CONNHANDLE)
    {
    // Store mapping
    connHandleMap[index]->connHandle = connHandle;

    // Convert address to string
    uint8_t *pAddr = (uint8_t *) Util_convertBdAddr2Str(addr);

    // Copy converted string to persistent connection handle list
    memcpy(connHandleMap[index]->strAddr, pAddr, B_STR_ADDR_LEN);

    return index;
    }
    }
    // No room if we get here
    return bleNoResources;
    }

    12.present code

    void disconnect_and_update_buffer(uint8 next_index)//disconnects the buffer and updates the contents of the buffer
    {
    uint8 s1;

    if(Util_isActive(&ack_clock))
    Util_stopClock(&ack_clock);

    dis_status=GAPRole_TerminateConnection(connHandleMap[cindex].connHandle);//GAP_CONNHANDLE_INIT

    scan_count=0;
    memset(ack_packet,0,sizeof(ack_packet));

    if (next_index!=0)
    {
    if(buffer_counter==next_index)
    {
    buffer_counter=writecount-readcount;

    if(buffer_counter==0 && buffer_counter2>0)
    gatdata=1;

    if(buffer_ext_store==1) // if values are restored from the external flash external flash will be erased
    {
    if(ext_addr_ch_bt==1)
    ext_addr_ch_bt=2;
    else if(ext_addr_ch_bt==2)
    ext_addr_ch_bt=1;
    write_single_data(ext_addr_ch_bt);

    buff_limit_erase();
    }

    if(buff_store==1) // if count is restored from the external flash it will be erased
    {
    DELAY_MS(100);
    buff_store=0;
    memset(write_store,0,sizeof(write_store));
    memset(read_store,0,sizeof(read_store));

    if (!isOpen)
    {
    isOpen = ExtFlash_open();
    }

    ExtFlash_erase(write_count_store,1);

    if (isOpen)
    {
    isOpen = false;
    ExtFlash_close();
    }
    }

    if(writecount==readcount && ((writecount>=2650 && ext_fl_part==0) || (writecount>=35500 && ext_fl_part==1)))
    {
    if(ext_addr_ch_bt==1)
    ext_addr_ch_bt=2;
    else if(ext_addr_ch_bt==2)
    ext_addr_ch_bt=1;
    write_single_data(ext_addr_ch_bt);

    buff_limit_erase();
    }
    }
    else if (next_index<buffer_counter)
    {
    data_read_count=data_read_count-next_index;
    readcount=readcount-data_read_count;
    buffer_counter=writecount-readcount;
    }
    connRole=0;
    }
    else if(first_data_read==1 && readcount>0)
    {
    readcount=readcount-1;
    }

    if(settings_changed==1) //All settings are saved here along with time
    {
    settings_changed=0;
    time_save();
    }

    dev_list_index=0; // all buffers involved in processing are cleared
    scanned_dyn_id_16=0;
    dev_counter=0;
    devices_discovered=0;
    data_read_count=0;
    memset(connected_device_address,0,sizeof(connected_device_address));
    memset(dest_addr,0,sizeof(dest_addr));
    memset(packet_to_send,0,sizeof(packet_to_send));
    memset(curr_addr,0,sizeof(curr_addr));
    memset(prev_addr,0,sizeof(prev_addr));
    memset(adv_data,0,sizeof(adv_data));
    memset(scanned_dyn_id,0,sizeof(scanned_dyn_id));

    for(s1=0;s1<DEV_LIST_SIZE;s1++)
    {
    scanned_coin_info[s1].DevList_index=0;
    scanned_coin_info[s1].RSSI=0;
    memset(scanned_coin_info[s1].addr1,0,GATEWAY_DATA);
    memset(scanned_coin_info[s1].dyn_id,0,2);
    scanned_coin_info[s1].static_id=0;
    //memset(scanned_coin_info[s1].static_id,0,2);
    scanned_coin_info[s1].in_range=0;
    scanned_coin_info[s1].dyn_id_16=0;
    }

    for (s1=0;s1<DEFAULT_MAX_SCAN_RES;s1++)
    {
    devList[s1].addrType=0;
    devList[s1].eventType=0;
    memset(devList[s1].addr,0,GATEWAY_DATA);
    }

    first_data_read=0;
    }

    //disconnects the buffer and updates the contents of the buffer for rev communication
    void disconnect_and_update_gateway_buffer(uint8 next_index1)//disconnects the buffer and updates the contents of the buffer
    {
    uint8 s1;

    if(Util_isActive(&ack_clock))
    Util_stopClock(&ack_clock);

    GAPRole_TerminateConnection(connHandleMap[cindex].connHandle);

    scan_count=0;
    memset(ack_packet,0,sizeof(ack_packet));

    if (next_index1!=0)
    {
    if(buffer_counter2==next_index1)
    {
    memset(gateway_buffer,0,sizeof(gateway_buffer));
    buffer_counter2=0;

    gatdata=0;
    // getset_dynid_16=0;
    }
    connRole=0;
    }

    dev_list_index=0;
    scanned_dyn_id_16=0;
    dev_counter=0;
    devices_discovered=0;
    memset(connected_device_address,0,sizeof(connected_device_address));
    memset(dest_addr,0,sizeof(dest_addr));
    memset(packet_to_send1,0,sizeof(packet_to_send1));
    memset(curr_addr,0,sizeof(curr_addr));
    memset(prev_addr,0,sizeof(prev_addr));
    memset(adv_data,0,sizeof(adv_data));
    memset(scanned_dyn_id,0,sizeof(scanned_dyn_id));

    for(s1=0;s1<DEV_LIST_SIZE;s1++)
    {
    scanned_coin_info[s1].DevList_index=0;
    scanned_coin_info[s1].RSSI=0;
    memset(scanned_coin_info[s1].addr1,0,GATEWAY_DATA);
    memset(scanned_coin_info[s1].dyn_id,0,2);
    scanned_coin_info[s1].static_id=0;
    //memset(scanned_coin_info[s1].static_id,0,2);
    scanned_coin_info[s1].in_range=0;
    scanned_coin_info[s1].dyn_id_16=0;
    }

    for (s1=0;s1<DEFAULT_MAX_SCAN_RES;s1++)
    {
    devList[s1].addrType=0;
    devList[s1].eventType=0;
    memset(devList[s1].addr,0,GATEWAY_DATA);
    }
    }

    12.the changes i have done in my code to achieve simultaneous connection

    void disconnect_and_update_buffer(uint8 next_index, uint16_t chandle) // Added chandle parameter
    {
    uint8 s1;
    int cindex = -1; // Added cindex declaration

    // Find the connection index based on the chandle
    for (int i = 0; i < MAX_NUM_BLE_CONNS; i++)
    {
    if (connHandleMap[i]->connHandle == chandle)
    {
    cindex = i;
    break;
    }
    }

    if (cindex == -1)
    {
    // Connection handle not found, handle error
    return; // Or log an error, etc.
    }

    if (Util_isActive(&ack_clock))
    Util_stopClock(&ack_clock);

    dis_status = GAPRole_TerminateConnection(connHandleMap[cindex]->connHandle);

    scan_count=0;
    memset(ack_packet,0,sizeof(ack_packet));

    if (next_index!=0)
    {
    if(buffer_counter==next_index)
    {
    buffer_counter=writecount-readcount;

    if(buffer_counter==0 && buffer_counter2>0)
    gatdata=1;

    if(buffer_ext_store==1) // if values are restored from the external flash external flash will be erased
    {
    if(ext_addr_ch_bt==1)
    ext_addr_ch_bt=2;
    else if(ext_addr_ch_bt==2)
    ext_addr_ch_bt=1;
    write_single_data(ext_addr_ch_bt);

    buff_limit_erase();
    }

    if(buff_store==1) // if count is restored from the external flash it will be erased
    {
    DELAY_MS(100);
    buff_store=0;
    memset(write_store,0,sizeof(write_store));
    memset(read_store,0,sizeof(read_store));

    if (!isOpen)
    {
    isOpen = ExtFlash_open();
    }

    ExtFlash_erase(write_count_store,1);

    if (isOpen)
    {
    isOpen = false;
    ExtFlash_close();
    }
    }

    if(writecount==readcount && ((writecount>=2650 && ext_fl_part==0) || (writecount>=35500 && ext_fl_part==1)))
    {
    if(ext_addr_ch_bt==1)
    ext_addr_ch_bt=2;
    else if(ext_addr_ch_bt==2)
    ext_addr_ch_bt=1;
    write_single_data(ext_addr_ch_bt);

    buff_limit_erase();
    }
    }
    else if (next_index<buffer_counter)
    {
    data_read_count=data_read_count-next_index;
    readcount=readcount-data_read_count;
    buffer_counter=writecount-readcount;
    }
    connRole=0;
    }
    else if(first_data_read==1 && readcount>0)
    {
    readcount=readcount-1;
    }

    if(settings_changed==1) //All settings are saved here along with time
    {
    settings_changed=0;
    time_save();
    }

    dev_list_index=0; // all buffers involved in processing are cleared
    scanned_dyn_id_16=0;
    dev_counter=0;
    devices_discovered=0;
    data_read_count=0;
    memset(connected_device_address,0,sizeof(connected_device_address));
    memset(dest_addr,0,sizeof(dest_addr));
    memset(packet_to_send,0,sizeof(packet_to_send));
    memset(curr_addr,0,sizeof(curr_addr));
    memset(prev_addr,0,sizeof(prev_addr));
    memset(adv_data,0,sizeof(adv_data));
    memset(scanned_dyn_id,0,sizeof(scanned_dyn_id));

    for(s1=0;s1<DEV_LIST_SIZE;s1++)
    {
    scanned_coin_info[s1].DevList_index=0;
    scanned_coin_info[s1].RSSI=0;
    memset(scanned_coin_info[s1].addr1,0,GATEWAY_DATA);
    memset(scanned_coin_info[s1].dyn_id,0,2);
    scanned_coin_info[s1].static_id=0;
    //memset(scanned_coin_info[s1].static_id,0,2);
    scanned_coin_info[s1].in_range=0;
    scanned_coin_info[s1].dyn_id_16=0;
    }

    for (s1=0;s1<DEFAULT_MAX_SCAN_RES;s1++)
    {
    devList[s1].addrType=0;
    devList[s1].eventType=0;
    memset(devList[s1].addr,0,GATEWAY_DATA);
    }

    first_data_read=0;
    }

    //disconnects the buffer and updates the contents of the buffer for rev communication
    void disconnect_and_update_gateway_buffer(uint8 next_index1, uint16_t chandle)//disconnects the buffer and updates the contents of the buffer
    {
    uint8 s1;
    int cindex = -1; // Added cindex declaration

    // Find the connection index based on the chandle
    for (int i = 0; i < MAX_NUM_BLE_CONNS; i++)
    {
    if (connHandleMap[i]->connHandle == chandle)
    {
    cindex = i;
    break;
    }
    }

    if (cindex == -1)
    {
    // Connection handle not found, handle error
    return; // Or log an error, etc.
    }

    if (Util_isActive(&ack_clock))
    Util_stopClock(&ack_clock);

    GAPRole_TerminateConnection(connHandleMap[cindex]->connHandle);

    scan_count=0;
    memset(ack_packet,0,sizeof(ack_packet));

    if (next_index1!=0)
    {
    if(buffer_counter2==next_index1)
    {
    memset(gateway_buffer,0,sizeof(gateway_buffer));
    buffer_counter2=0;

    gatdata=0;
    // getset_dynid_16=0;
    }
    connRole=0;
    }

    dev_list_index=0;
    scanned_dyn_id_16=0;
    dev_counter=0;
    devices_discovered=0;
    memset(connected_device_address,0,sizeof(connected_device_address));
    memset(dest_addr,0,sizeof(dest_addr));
    memset(packet_to_send1,0,sizeof(packet_to_send1));
    memset(curr_addr,0,sizeof(curr_addr));
    memset(prev_addr,0,sizeof(prev_addr));
    memset(adv_data,0,sizeof(adv_data));
    memset(scanned_dyn_id,0,sizeof(scanned_dyn_id));

    for(s1=0;s1<DEV_LIST_SIZE;s1++)
    {
    scanned_coin_info[s1].DevList_index=0;
    scanned_coin_info[s1].RSSI=0;
    memset(scanned_coin_info[s1].addr1,0,GATEWAY_DATA);
    memset(scanned_coin_info[s1].dyn_id,0,2);
    scanned_coin_info[s1].static_id=0;
    //memset(scanned_coin_info[s1].static_id,0,2);
    scanned_coin_info[s1].in_range=0;
    scanned_coin_info[s1].dyn_id_16=0;
    }

    for (s1=0;s1<DEFAULT_MAX_SCAN_RES;s1++)
    {
    devList[s1].addrType=0;
    devList[s1].eventType=0;
    memset(devList[s1].addr,0,GATEWAY_DATA);
    }
    }

    I m facing issue when coin 2 generates the data its start advertising and coin 1 receives request and send acknowledgment to coin 2.
    but coin 2 not receiving acknowledgment (the flow is not coming to SIMPLEPROFILE_CHAR1)and not sending data to coin 1. without these changes its working properly.please guide me for implementing simultaneous connection.