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.

automatic port discovering through SDP.....

Other Parts Discussed in Thread: MSP430F5438A, CC2564

Hello,


The device that we are developing consists of BT modules acting as a client and transmitting data (SPP profile) to a BT server that mirror this data through a virtual COM port to a PC. In order to autoconnect the client to the server and knowing the port number to connect with, I need to implement an SDP connection. I already implemented it on client side and it correcly works. I tested it with a Qt/Android application acting as a server. Now i need to implement the SDP connection server side. Following i posto the C++/Qt code initializing the SDP services. How can i translate it in MSP430 code? Can someone post some code?

I'm using CC2564B+MSP430F5438A and Bluetopia stack.

Qt Code that starts the server and initializes SDP:

void btServer::startServer(const QBluetoothAddress& localAdapter)

{
    if (rfcommServer)
        return;

    //! [Create the server]
    rfcommServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
    connect(rfcommServer, SIGNAL(newConnection()), this, SLOT(clientConnected()));
    bool result = rfcommServer->listen(localAdapter);

    qDebug("server is listening to port:%d",rfcommServer->serverPort());
qDebug("server created");

    //! [Create the server]

    //serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010);

    //! [Class Uuuid must contain at least 1 entry]
    QBluetoothServiceInfo::Sequence classId;

    classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
    serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,classId);

    classId.prepend(QVariant::fromValue(QBluetoothUuid(serviceUuid)));

    serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
    serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,classId);
    //! [Class Uuuid must contain at least 1 entry]


    //! [Service name, description and provider]
    serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Nemesi Server"));
    serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription,tr("Nemesi SDP"));
    serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("LISiN - Politecnic of Turin"));
    //! [Service name, description and provider]

    //! [Service UUID set]
    serviceInfo.setServiceUuid(QBluetoothUuid(serviceUuid));
    //! [Service UUID set]

    //! [Service Discoverability]
    QBluetoothServiceInfo::Sequence publicBrowse;
    publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
    serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList,publicBrowse);
//! [Service Discoverability]

    //! [Protocol descriptor list]
    QBluetoothServiceInfo::Sequence protocolDescriptorList;
    QBluetoothServiceInfo::Sequence protocol;
    protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
    protocolDescriptorList.append(QVariant::fromValue(protocol));
    protocol.clear();
    protocol<<QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))<<QVariant::fromValue(quint8(rfcommServer->serverPort()));
    protocolDescriptorList.append(QVariant::fromValue(protocol));
    serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,protocolDescriptorList);
    //! [Protocol descriptor list]

    //! [Register service]
    serviceInfo.registerService(localAdapter);
    //    serviceInfo.registerService();
    //! [Register service]

}



Thanks in advance,

GLC

  • Hi GLC,

    If I understood correctly, you need to register the SPP Server with the local SDP database on the MSP430. Is my understanding correct?

    If so, it's already in place. Please see SPPDemo.c from the sample apps (function: OpenServer). The API that does it is: "SPP_Register_Generic_SDP_Record"

    You can also check the BluetopiaCoreAPI.pdf section 2.4 for the full list of SDP APIs .

    Regards,
    Gigi Joseph.
  • I tried with this function but the client is not able to discover the port number to connect with.

    I need to connect to a port number with a certain UUID assigned while the function mentioned above doesn't pass any UUID because the SDPservicerecord passed is nul. How can i pass it?

    Can you post some code on how to initialize and pass the SDPservice record with a certain UUID?

    Thanks in advance,

    GLC

  • Hi GLC,


    [Q] I tried with this function but the client is not able to discover the port number to connect with.
    [A] This is very weird. Are you doing "Open <port>" on the SPP Demo sample app? I just tried it , and I could get the below response:


    As you can see, it is returning channel number "1". 

    [Q] I need to connect to a port number with a certain UUID assigned while the function mentioned above doesn't pass any UUID because the SDPservicerecord passed is nul. How can i pass it?
    [A] This is because the SPP service has a standard UUID (Service Class ID) = 0x1101
    You can also take a look at: SPP_Register_SDP_Record

    Regards,
    Gigi Joseph.

  • Hi Gigi,

    It's obvious that id I open the server on port 1, from the client side i will be able to connect to the server on the port 1 but my application need to query the port number to connect with because it is needed that the client can work either connected on a CC2564 based server or directly to an Android tablet acting as a server. So I need to use no default UUID.

    If I understood correctly, to set the UUID, i need to call the SPP_Register_SDP_Record function instead of the SPP_Register_Generic_SDP_Record function passing a proper SDP service record conataining one (or more) UUID entry. If it is true, can I leave NULL the SDP_Data_Element_t field in the SDPservicerecord? I will post some code.

    Thanks for the reply,

    GLC
  • Hi all,

    i tried to initialize the SDP service with the following code after opening the server port:

    /* Initialize the Service Class UUIDs. */

    SPP_SDP_Service_Record_t SDPServiceRecord;
    SDP_UUID_Entry_t SDPUUIDEntry[2];

    /* First let's build the UUID 32 value(s). */
    SDPUUIDEntry[0].SDP_Data_Element_Type = deUUID_128;
    /* First let's build the UUID 32 value(s). */
    SDPUUIDEntry[1].SDP_Data_Element_Type = deUUID_128;
    //for Sensor Units from 1 to 4
    ASSIGN_SDP_UUID_128(SDPUUIDEntry[0].UUID_Value.UUID_128, 0xe8, 0xe1, 0x0f, 0x95, 0x1a, 0x70, 0x4b, 0x27, 0x9c, 0xcf, 0x02, 0x01, 0x02, 0x64, 0xe9, 0xc8);
    //for Sensor Units from 5 to 7
    ASSIGN_SDP_UUID_128(SDPUUIDEntry[1].UUID_Value.UUID_128, 0x39, 0x23, 0xcf, 0x40, 0x73, 0x16, 0x42, 0x9a, 0x5c, 0x41, 0x7e, 0x7d, 0xc4, 0x9a, 0x83, 0x16);

    SDPServiceRecord.NumberServiceClassUUID=sizeof(SDPUUIDEntry)/sizeof(SDPUUIDEntry[0]);
    SDPServiceRecord.SDPUUIDEntries=SDPUUIDEntry;
    SDPServiceRecord.ProtocolList=NULL;

    /* Register the SDP Record. */
    ret_val = SPP_Register_SDP_Record(BluetoothStackID, SerialPortID, &SDPServiceRecord, ServiceName, &SPPServerSDPHandle);

    The debug terminal of the SPPDemo example give me the following error:

    "Unable to Register Server SDP Record, Error = -1.
    Function Error."

    Someone can help me? I supposed that the error is on the SDPServiceRecord initialization but i don't know how to set it correctly.....
  • Hi,

    The "Function Error" is probably because of NULL or Empty "ServiceName"

    Regards,
    Gigi Joseph.