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.

bluetopia, how to response pin code automatically?

Other Parts Discussed in Thread: MSP430F5438A

hi,Stonestreet One

Many android phone do not support simple secure pair, so i download sppdemo with default and run it with server mode.when android phone pair with kit, i must input pin code like 1234,and console reponse like:

atPINCodeRequest: 0xF8D0BDC0AAEB
Respond with: PINCodeResponse

so i input PINCodeResponse 1234 to pair with android phone.

This pairing procedure is operated on kit by manual , how to operate automatically(not sample secure pair)? or else, where can I get pin code in sppdemo?

kit:MSP-EXP5438+msp430F5438A+PAN1323

sdk:CC256x_MSP430_Bluetopia_SDK_v1-2_Setup
example:sppdemo

  • Hello Kun,

    You can respond with a predetermined PIN code programatically  using the logic of PINCodeResponse routine and using it under 

    case atPINCodeRequest:

    -----

    The heart of the code would be:

    /* Initialize the PIN code. */
    ASSIGN_PIN_CODE(PINCode, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); //change with what you want the pin code to be

    /* Populate the response structure. */
    GAP_Authentication_Information.GAP_Authentication_Type = atPINCode;
    GAP_Authentication_Information.Authentication_Data_Length =xxx; //change with how long you want the pin code to be. xxx=4 would get you 0000 as PIN code here.
    GAP_Authentication_Information.Authentication_Data.PIN_Code = PINCode;

    /* Submit the Authentication Response. */
    Result = GAP_Authentication_Response(BluetoothStackID, CurrentRemoteBD_ADDR, &GAP_Authentication_Information);

    ----

    Hope this helps,

    Stonestreet One.

  • Hello,

    I am using MSP-EXP430F5438 and PAN1323ETU. Even I want to enter pin code "0000" automatically to connect PAN1323 to my PC. I carried out steps as you mentioned above but still I get message on Tera Term as : Usage: PINCodeResponse [PIN Code]. My edited PinCodeResponse is as follows: 

    /* Initialize the PIN code. */
    ASSIGN_PIN_CODE(PINCode, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    BTPS_MemCopy(&PINCode, TempParam->Params[0].strParam, BTPS_StringLength(TempParam->Params[0].strParam));

    /* Populate the response structure. */
    GAP_Authentication_Information.GAP_Authentication_Type = atPINCode;
    GAP_Authentication_Information.Authentication_Data_Length =4 ;
    GAP_Authentication_Information.Authentication_Data.PIN_Code = PINCode;

    /* Submit the Authentication Response. */

  • Hello Neha,

    Can you please post the code under the following case statement? 

    case atPINCodeRequest:

    Also, you should not call BTPS_MemCopy(&PINCode,...) as you will be overwriting the PINCode. You should remove all code that prompts the user to input from command line.

    Best Regards,

    Stonestreet One. 



  • Thank your for your reply. The code under the case atPINCodeRequest is as follows: 

    case atPINCodeRequest:
    /* A pin code request event occurred, first display */
    /* the BD_ADD of the remote device requesting the pin.*/
    BD_ADDRToStr(GAP_Event_Data->Event_Data.GAP_Authentication_Event_Data->Remote_Device, Callback_BoardStr);
    Display(("\r\n"));
    Display(("atPINCodeRequest: %s\r\n", Callback_BoardStr));

    /* Note the current Remote BD_ADDR that is requesting */
    /* the PIN Code. */
    CurrentRemoteBD_ADDR = GAP_Event_Data->Event_Data.GAP_Authentication_Event_Data->Remote_Device;

    /* Inform the user that they will need to respond with*/
    /* a PIN Code Response. */
    Display(("Respond with: PINCodeResponse\r\n"));
    PINCodeResponse((jkh));

    And code under PINCodeResponse is as follows:

    static int PINCodeResponse(ParameterList_t *TempParam)
    {
    int Result;
    int ret_val;
    PIN_Code_t PINCode;
    GAP_Authentication_Information_t GAP_Authentication_Information;

    /* First, check that valid Bluetooth Stack ID exists. */
    if(BluetoothStackID)
    {
    /* First, check to see if there is an on-going Pairing operation */
    /* active. */
    if(!COMPARE_BD_ADDR(CurrentRemoteBD_ADDR, NullADDR))
    {
    /* Make sure that all of the parameters required for this */
    /* function appear to be at least semi-valid. */
    if((TempParam) && (TempParam->NumberofParameters > 0) && (TempParam->Params[0].strParam) && (BTPS_StringLength(TempParam->Params[0].strParam) > 0) && (BTPS_StringLength(TempParam->Params[0].strParam) <= sizeof(PIN_Code_t)))
    {
    /* Parameters appear to be valid, go ahead and convert the */
    /* input parameter into a PIN Code. */

    /* Initialize the PIN code. */
    ASSIGN_PIN_CODE(PINCode, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    BTPS_MemCopy(&PINCode, TempParam->Params[0].strParam, BTPS_StringLength(TempParam->Params[0].strParam));

    /* Populate the response structure. */
    GAP_Authentication_Information.GAP_Authentication_Type = atPINCode;
    GAP_Authentication_Information.Authentication_Data_Length =4 ;//(Byte_t)(BTPS_StringLength(TempParam->Params[0].strParam));
    GAP_Authentication_Information.Authentication_Data.PIN_Code = PINCode;

    /* Submit the Authentication Response. */

    Result = GAP_Authentication_Response(BluetoothStackID, CurrentRemoteBD_ADDR, &GAP_Authentication_Information);

    /* Check the return value for the submitted command for */
    /* success. */
    if(!Result)
    {
    /* Operation was successful, inform the user. */
    Display(("GAP_Authentication_Response(), Pin Code Response Success.\r\n"));

    /* Flag success to the caller. */
    ret_val = 0;
    }
    else
    {
    /* Inform the user that the Authentication Response was */
    /* not successful. */
    Display(("GAP_Authentication_Response() Failure: %d.\r\n", Result));

    ret_val = FUNCTION_ERROR;
    }

    /* Flag that there is no longer a current Authentication */
    /* procedure in progress. */
    ASSIGN_BD_ADDR(CurrentRemoteBD_ADDR, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
    }
    else
    {
    /* One or more of the necessary parameters is/are invalid. */
    DisplayUsage("PINCodeResponse [PIN Code]");

    ret_val = INVALID_PARAMETERS_ERROR;
    }
    }
    else
    {
    /* There is not currently an on-going authentication operation,*/
    /* inform the user of this error condition. */
    Display(("PIN Code Authentication Response: Authentication not in progress.\r\n"));

    ret_val = FUNCTION_ERROR;
    }
    }
    else
    {
    /* No valid Bluetooth Stack ID exists. */
    ret_val = INVALID_STACK_ID_ERROR;
    }

    return(ret_val);
    }

  • Hello Neha,

    In the code that you attached, please make the following changes.

    Comment out these lines

    //Display(("\r\n"));
    //Display(("atPINCodeRequest: %s\r\n", Callback_BoardStr));

    //Display(("Respond with: PINCodeResponse\r\n"));

    //BTPS_MemCopy(&PINCode, TempParam->Params[0].strParam, BTPS_StringLength(TempParam->Params[0].strParam));

    And 

    change 

    if((TempParam) && (TempParam->NumberofParameters > 0) && (TempParam->Params[0].strParam) && (BTPS_StringLength(TempParam->Params[0].strParam) > 0) && (BTPS_StringLength(TempParam->Params[0].strParam) <= sizeof(PIN_Code_t)))

    to

    if(1)

    ----

    the idea is to feed a hardcoded PIN code value in this routine. 

    ASSIGN_PIN_CODE(PINCode, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); //for PIN code of 1234 this would be (PINCode, 1,2, 3, 4, ....) and length below would be 4

    macro will set up the bytes of PINCode 

    GAP_Authentication_Information.Authentication_Data_Length =4;

    will configure how many bytes are valid (e.g. if you wanted PIN to be 00000 this would be 5)

    Hope this helps. Let us know if there are any errors.

    Best Regards,

    Stonestreet One. 

  • What I did was very simple. First create a structure

    char passcode[] = "0000";
    Parameter_t code={passcode,1};
    ParameterList_t codelist = {1,{passcode,1}};

    Then add the following below under "case aPINCodeRequest":

    PINCodeResponse(&codelist);

    It works for me.

  • Hello, 

    Thanks for this suggestion. I made the changes told by you and now the pin code gets accepted. But further the required link key does not get stored and PAN1323 does not get paired with the PC. Can you tell the necessary changes to be made further in the code? Thanks in advance.

    After entering pin code automatically I get the following response in tera term:

    GAP_Authentication_Response(), Pin Code Response Success.

    Client>
    SPP Open Confirmation, ID: 0x0001, Status 0x0002.

    Client>

  • Hi stonestreet one,

    i also tried to change the code for automatic pincode-response (same setting as threadstarter) and came to the same solution as you posted in this thread, but there seems to be an issue and i cant find the problem...

    when i try to connect with the phone and use the original pincoderesponse 0000 everything works fine.
    when in try to connect with the phone and use the new pincoderesponseAuto the phone throws an error because pincode was not correkt ...

    i changed the code in the PinCodeResponseAuto() with this main changes to the original method:
    - if(1)
    - //BTPS_MemCopy...
    - Data_Length   = 4;

    here the full code snipet:

    if(1)
    {

    /* Parameters appear to be valid, go ahead and convert the */
    /* input parameter into a PIN Code. */

    /* Initialize the PIN code. */
    ASSIGN_PIN_CODE(PINCode, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    //BTPS_MemCopy(&PINCode, TempParam->Params[0].strParam, BTPS_StringLength(TempParam->Params[0].strParam));

    /* Populate the response structure. */
    GAP_Authentication_Information.GAP_Authentication_Type = atPINCode;
    GAP_Authentication_Information.Authentication_Data_Length = 4;
    GAP_Authentication_Information.Authentication_Data.PIN_Code = PINCode;

    /* Submit the Authentication Response. */
    Result = GAP_Authentication_Response(BluetoothStackID, CurrentRemoteBD_ADDR, &GAP_Authentication_Information);

    hope you can help me!? thanks.

  • now i also tried the workaround posted before:

    static char passcode[] = "0000";
    static Parameter_t code={passcode,1};
    static ParameterList_t codelist = {1,{passcode,1}};
    PINCodeResponse(&codelist);

    works also for me!