DA14531 allowing to connect without pairing and allowing to send or receive data from BLE Application.

Hi Team,

When i click on Connect for the first time pairing pop-up is coming, even if i not entered passcode also it started communicating with BLE Application.

In my code i have set

 user_app_on_init() 

{

codeless_env.pin= 123456;

}

Iam expecting, after entering pairing code only it should connect and start communicating with Application.

Pls help me in fixing this issue.

Regards,

Laxmi Narayana.

  • Hi Laxmi,

    Thank you for posting  your question online.
    Could you please clarify the Codeless SDK version you are working with?
    Did you use prior the AT+SEC command to set the Security level you want? Did you explicitly use the AT+PIN command to set the PIN or only inside your code?
    Have you changed the Services Permissions for this project? By default all Services are accessible without Authorization required, you can change that.
    Is your device central or peripheral?
    Please share the exact AT command sequence you used so we can try to replicate this.

    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank for response, Iam using codeless Version:6.380.14.22.

    we are not using any AT commands like AT+SEC, AT+PIN and we disabled all AT commands.

    I not touched any services related part in my code.

    My device is central.

    Pls find the attached Zip file.

    codeless_5xx.zip

    Regards,

    Laxmi Narayana

  • Hi Laxmi,

    Thank you for the reply.

    we are not using any AT commands like AT+SEC, AT+PIN and we disabled all AT commands.

    What is the point of using the Codeless SDK if you have disabled all AT commands? Why not create a project with the Generic SDK6?
    Please check our Central with Security example: BLE_SDK6_examples/connectivity/central_Security_Demo at main · dialog-semiconductor/BLE_SDK6_examples (github.com)

    Iam using codeless Version:6.380.14.22.
    My device is central.

    Please refer on the Codeless SDK Release Notes:

    The Bonding support for the Central role in Codeless is supported from SDK v6.380.16.55 version and later. 
    You will have to define the CFG_BOND_CMD_SUPPORTED macro in the da1458x_config_advanced.h file.

    On the SDK v6.380.14.22, if you define the CFG_BOND_CMD_SUPPORTED macro and build the project you should receive the following in the output window:


    You should either migrate into a later Codeless SDK version or use the Generic SDK6 to create your application since you are not utilizing the AT commands. 

    Best Regards,
    OV_Renesas

  • Hi,

    I tried your suggestion, but it not worked and later i realized that my device is peripheral. 

    my requirement is after entering pairing code only the application should able to connect and start communicating with Application.

    is it possible with DA14531MOD and codeLess: v6.380.18.63.

    Regards,

    Laxmi Narayana.

  • Hi Laxmi,

    Thank you for the reply.

    my requirement is after entering pairing code only the application should able to connect and start communicating with Application.

    is it possible with DA14531MOD and codeLess: v6.380.18.63.

    Please correct me if I am mistaken. The desired scenario is:
    1) DA14531MOD is in Peripheral mode with Security, we will call it P0
    2) Your SmartConsole is the Central device, we will call it C0
    3) The C0 sends a CONNECT_IND packet to the P0 to initiate the connection.
    4) P0 accepts the connection and sends a security request to C0
    5) Pairing procedure is done with the PIN
    6) Upon disconnection, no other device other than C0 should be able to connect again to the P0.

    The above scenario, should be possible but it would need modifications of the Codeless SDK.
    Let me check on this and I will get back to you.
    My main concern is that Smartphones (C0) constantly change their Bluetooth Address which would make it hard to use White listing or accept CONNECT_IND packets only from this specific BDA.

    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank you reply,

    • In my using sdk codeLess 6.380.14.22. with this code when i trying to pair with P0,  P0 allowing to connect C0 without entering the pairing code.
    • My second issue is i have one LED which iam used as connection status for the user, so i enabling LED GPIO using  set_connection_indicator_output(true); in user_on_connection() function as shown below. but i notice that LED turning on in paring process. ideally LED should turn ON when user connected to the device. 

    void user_on_connection(uint8_t connection_idx, struct gapc_connection_req_ind const* param)
    {
        #if defined(USE_AT_BINARY_MODE)
        user_reset_peer_status_vars();
        #endif
        
        #ifdef USE_AT_HNDL
        if (user_is_handler_enabled(CONNECTION_EVENT_HANDLER))
        {
        user_execute_event_handler_commands((char*)user_get_handler_command_string(CONNECTION_EVENT_HANDLER));
        }
        #endif
        #if defined(USE_AT_CONPAR) && !defined(USE_AT_BINARY_MODE)
        struct connection_configuration_t *p_conf=&codeless_env.conn_conf;
        #endif
        static int i=0;
        codeless_env.event_trigger=true;
        //Call the default handler for this event
        if (codeless_env.bt_role != GAP_ROLE_CENTRAL)
        {
        if (app_env[connection_idx].conidx != GAP_INVALID_CONIDX)
        {
        codeless_env.connection_index=connection_idx;
        
        user_exit_sleep();
        if(sleep_timer!=NULL)
        app_easy_timer_cancel(sleep_timer);
        sleep_timer=0;
        features_timer = app_easy_timer(60, get_features);
        // Enable the created profiles/services
        if(!i)
        {
        i=1;
        app_prf_enable(connection_idx);
        }
        #if BLE_APP_SEC
        if ((user_default_hnd_conf.security_request_scenario == DEF_SEC_REQ_ON_CONNECT)
        && (BLE_APP_SEC) && (codeless_env.pin != 0)) {
        app_easy_security_request(connection_idx);
        }
        #endif
        #ifdef USE_AT_RSSI
        // Send a message to retrieve the rssi value and start
        // a timer to retrieve the rssi value regularly
        get_rssi();
        #endif
        
        
        #if !defined(USE_AT_BINARY_MODE)
        /* If sps is enabled, param update is performed at later stage */
        #ifdef USE_AT_CONPAR
        if(p_conf->param_update_enable)
        user_param_update_start(connection_idx);
        #else
        user_param_update_start(connection_idx);
        #endif //USE_AT_CONPAR
        
        user_gattc_exc_mtu_cmd(connection_idx);
        #endif //!USE_AT_BINARY_MODE
        
        #ifdef USE_AT_EVENT
        if (app_is_event_enabled(CONNECTION_EVENT))
        #endif //USE_AT_EVENT
        #ifdef BLE_DEV_DEBUG
        {
        send_to_local(CONNECTION_SUCCESSFUL_STRING);
        
        }
        #endif
        #ifdef AUTO_BIN_MODE_ON_CONNECT
        #ifdef BLE_DEV_DEBUG
        user_cmd_interpreter("AT+BINREQ\r",sizeof("AT+BINREQ\r"),CMD_SRC_REMOTE); //RCVD
        //user_cmd_interpreter("AT+BINREQACK\r",sizeof("AT+BINREQACK\r"),CMD_SRC_LOCAL); //RCVD
        #endif
        #endif
        
        } else {
        // No connection has been established, restart advertising
        user_advertise();
        //GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_9, OUTPUT, PID_GPIO, false); //LED OFF
        
        }
        
        }
        else // if(codeless_env.bt_role == GAP_ROLE_CENTRAL_CODELESS)
        {
        codeless_env.connection_index=connection_idx;
        if(sleep_timer!=NULL)
        app_easy_timer_cancel(sleep_timer);
        sleep_timer=0;
        //user_gattc_exc_mtu_cmd(connection_idx);
        #ifdef USE_AT_EVENT
        if (app_is_event_enabled(CONNECTION_EVENT))
        #endif
        {
        send_to_local(CONNECTION_SUCCESSFUL_STRING);
        }
        
        #ifdef USE_AT_RSSI
        // Send a message to retrieve the rssi value and start
        // a timer to retrieve the rssi value regularly
        get_rssi();
        #endif
        
        // Make a GATT characteristic discovery to identify the 16bit attribute handles of the three
        // CodeLess characteristics
        codeless_env.gap_activity = DISCOVERING;
        user_gatt_discover_chars();
        
        }
        //GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_9, OUTPUT, PID_GPIO, true); //LED ON
        // Set the connection indication if any
        set_connection_indicator_output(true);
        
        // A connection parameter request must comply with certain rules for apple phones.
        // TODO:check is the following line is necessary for iphones
        // app_param_update_op(0,24,48,0, 200,12,12);
    
    }

  • Hi Laxmi,

    Thank you for the reply.

    using sdk codeLess 6.380.14.22.

    Apologies, but I worked on the latest Codeless SDK you mentioned on your initial post:

    is it possible with DA14531MOD and codeLess: v6.380.18.63.

    We added 3 custom AT commands that will enable/disable the Pairing option upon connection, and 1 AT command to check if the status is enabled or disabled.

    Changes required on SDK v6.380.18.63:
    On user_at_commands.h file:

    #define USE_AT_PR_MD    // This is a new set of AT commands 
     
    .
    .
    .
    //On the AT_COMMAND_ID_t typedef enum add the following:
    #ifdef USE_AT_PR_MD
        AT_EN_PR_MD,
        AT_DIS_PR_MD,
        AT_GET_PR_MD,
    #endif 
        AT_INVALID, /**< Command to execute in case of an invalid command. */
        AT_LAST_VALUE /**< Enumeration length. */
    } AT_COMMAND_ID_t;
    
    //At the end of the file declare the fuctions for the AT commands
    #ifdef USE_AT_PR_MD
    void user_at_en_pr_md(struct at_cmd_params_t* arg, char* reply_string);
    void user_at_dis_pr_md(struct at_cmd_params_t* arg, char* reply_string);
    void user_at_get_pr_md(struct at_cmd_params_t* arg, char* reply_string);
    #endif

    I have also removed the AT+CENTRAL and AT+GAPSCAN commands since you are not going to use the DA14531MOD in central role and we needed more space for the new AT commands.
    For memory issues, I have also removed the SUOTA feature from user_modules_config.h and user_profiles_config.h files.
    On user_codeless_env.h file I added the following on the struct codeless_env_t:
    #ifdef USE_AT_PR_MD
        bool is_pr_md_en;
    #endif 

    On user_codeless.c file, on the user_app_on_pairing_request at the start of the function I added:
    void user_app_on_pairing_request(uint8_t conidx, struct gapc_bond_req_ind const *param)
    {
    #ifdef USE_AT_PR_MD
        // When a connection attempt is made this function will be called only if 
        // a pairing has not taken placed already. Therefore if pairing mode is disable the device 
        // should just disconnect
        if (!codeless_env.is_pr_md_en)
        {
             // Disconnect
            app_easy_gap_disconnect(0);
             app_env[0].pairing_in_progress = false;
        }
    #endif 	
    .
    .
    .

    On the user_at_commands.c file, at the at_command_characteristics_t struct I added:
    #ifdef USE_AT_PR_MD
    		{ AT_EN_PR_MD		  ,  0,  0, "ENPRMD"			, user_at_en_pr_md			},
    		{ AT_DIS_PR_MD		,  0,	 0, "DISPRMD"			, user_at_dis_pr_md			},
    		{ AT_GET_PR_MD   ,  0,  0,  "GETPRMD"		, user_at_get_pr_md			},
    #endif 	

    On the same file I added the following functions:
    #ifdef USE_AT_PR_MD
    void user_at_en_pr_md(struct at_cmd_params_t* arg, char* reply_string)
    {
        codeless_env.is_pr_md_en = true;
        arg->success_flag = true;
    }
    
    void user_at_dis_pr_md(struct at_cmd_params_t* arg, char* reply_string) 
    {
        codeless_env.is_pr_md_en = false;
        arg->success_flag = true;
    }
    
    void user_at_get_pr_md(struct at_cmd_params_t* arg, char* reply_string) 
    {
        arch_sprintf(reply_string,(codeless_env.is_pr_md_en ? "ENABLED":"DISABLED"));
        arg->success_flag = true;
    }
    
    #endif // USE_AT_PR_MD

    Finally, on the da14531_config_advanced.h file I defined the CFG_USE_DYNAMIC_PRF_PERMS macro:
    /****************************************************************************************************************/
    /* If this macro is defined, CodeLess will change the permissions to access the custom profile database         */
    /* dynamically depending on the AT+SEC selection.This macro and CFG_BOND_CMD_SUPPORTED are mutually exclusive   */
    /****************************************************************************************************************/
    #if defined(__DA14531_01__)
    #define CFG_USE_DYNAMIC_PRF_PERMS
    #else // DA14531
    #if defined(CFG_BOND_CMD_SUPPORTED)
    #undef CFG_USE_DYNAMIC_PRF_PERMS
    #else 
    #define CFG_USE_DYNAMIC_PRF_PERMS // #define this macro here if you need dynamic profile permissions
    #endif 
    #if defined(CFG_USE_DYNAMIC_PRF_PERMS)
    #warning This feature will probably not fit in DA14531.Please remove some other feature to include this in
    #endif
    #endif


    After those changes you can compile and run the project.
    The new AT commands:

    AT+ENPRMD: Enable pairing mode. This command will enable the pairing mode and any new device that can provide the correct pin will be able to pair and will be added to the bonding database.

    AT+DISPRMD: Disable pairing mode. This command will disable the pairing mode. Any device that is not previously bonded will be disconnected when trying to pair. Any device that is already in the bonding database will be able to connect seamlessly. The pairing mode is disabled by default when the device starts.

    AT+GETPRMD: Get the pairing mode status. This command will print the current status of the pairing mode to the console. Either a "ENABLED" or "DISABLED" string will be printed.

    An example sequence of commands would be the following: AT+SEC = 0 (enable secure connections), AT+PIN=123456 (set a passkey),AT+ENPRMD (enable pairing mode) - perform a connection and pairing with mobile phone A - AT+DISPRMD (disable pairing mode).Mobile phone A will be able to connect without issues. No other phone will be able to pair since a disconnection will occur immediately.

    On my side I tested it and it works as expected.

    Regarding the LED question:

    My second issue is i have one LED which iam used as connection status for the user, so i enabling LED GPIO using  set_connection_indicator_output(true); in user_on_connection() function as shown below. but i notice that LED turning on in paring process. ideally LED should turn ON when user connected to the device. 

    The BLE devices, first establish a connection and if any of the Peripheral or Central wants to implement a security scenario they will need to send a security request.
    When you have used the AT+SEC command, the Peripheral (DA14531MOD) will automatically send the security request when the connection is established.

    Best Regards,
    OV_Renesas