API Reference | developer.brewmp.com API Reference | developer.brewmp.com


API Reference


Brew Release
Brew MP 1.0.2
See Also

This interface provides methods to control the Service Discovery module of the underlying Bluetooth driver.

Usage example:

   ===== To create an IBTServiceDiscovery object, see instruction in 
         class header file

   ===== To register signal
   // first create the signals; for example, use ISignalCBFactory_CreateSignal()
   // then register the signals:
   IBTServiceDiscovery_OnEventNotify (pMe->piBTSD, pMe->piSDEventSignal);

   ===== To search for up to 5 OBEX devices (OPP servers, ...) 
   ===== in the vicinity within 10 seconds
   pMe->pFoundDev = MALLOC (5*sizeof(BTDeviceInfo));
   IBTServiceDiscovery_StartDeviceSearch (pMe->piBTSD,
                                          5,    // 5 responses max
                                          10);  // ten seconds
   // The search would generate DEV_SEARCH_RESPONSE event if any OBEX devices 
   // are found.  When 5 different OBEX devices are found, or 10 seconds later, 
   // whichever comes first, DEV_SEARCH_COMPLETE event would get generated

   ===== To stop the on-going device search
   IBTServiceDiscovery_StopDeviceSearch (pMe->piBTSD);
   // DEV_SEARCH_COMPLETE would get generated

   ===== To search remote device's service DB for all records having
   ===== UUID value of 0x0003 (RFCOMM protocol UUID) and extract only
   ===== server channel numbers
   BTSvcSearchPattern pattern;
   pattern.nNumUUID16s = 1;
   pattern.UUID16[0] = AEEBT_PROT_RFCOMM;
   pattern.nNumUUID128s = 0;
   pattern.nNumAttributes = 1;
   IBTServiceDiscovery_StartServiceSearch (pMe->piBTSD, &remoteAddr, &pattern);
   // SVC_SEARCH_COMPLETE would get generated

   ===== To stop the on-going service search
   IBTServiceDiscovery_StopServiceSearch (pMe->piBTSD);
   // SVC_SEARCH_COMPLETE would get generated

   ===== To retrieve and handle events when Event signal is triggered:
   while (IBTServiceDiscovery_GetEvent (pMe->piBTSD, &dEvent,
                                        &dResult) != AEE_ENOMORE)
      switch (dEvent)
            while (IBTServiceDiscovery_GetNextResponse (
                      pMe->piBTSD, pMe->pFoundDev[ i ]) != AEE_ENOMORE)
               // if the search is over; it's possible now to request the
               // device name if necessary
               if (pMe->pFoundDev[ i ]->szName[0] == 0) // name not available
                  IBTServiceDiscovery_StartNameRequest (
                     pMe->piBTSD, pMe->pFoundDev[ i ]->bdAddr);
                  // when remote device sends its name, NAME_REQ_DONE event gets 
                  // generated; if remote device isn't connectable, this request
                  // would not complete quickly; user may wish to cancel 
                  // this request:
                  IBTServiceDiscovery_StopNameRequest (
                     pMe->piBTSD, pMe->pFoundDev[ i ]->bdAddr);
            IBTServiceDiscovery_GetName (pMe->piBTSD, pMe->pFoundDev[ i ]);
            IBTServiceDiscovery_GetNumFoundRecs (pMe->piBTSD, &numFoundRecs);
            if (numFoundRecs > 0)
               int nSize = 0;
               char* pszRecStr = NULL;
               IBTServiceDiscovery_GetSearchResult (pMe->piBTSD, NULL, 0, 
               pszRecStr = MALLOC (nSize);
               IBTServiceDiscovery_GetSearchResult (
                  pMe->piBTSD, pszRecStr, nSize, &nSize);
               // extract desired info from pszRecStr
            // assuming MyRecHandles is large enough
            IBTServiceDiscovery_GetMyRecordHandles (pMe->piBTSD, 
                                                    NULL, 0, &nNumHandles);
            IBTServiceDiscovery_GetMyRecordHandles (pMe->piBTSD, 
         // handle other events
   ISignalCtl_Enable (pMe->piSDEventSignalCtl); // re-enable signal

   ===== To register your proprietary OPP service which is 
   ===== implemented over SPP, first enable SPP server using
   ===== IBTSPPSRV_EnableService() and obtain the server channel number,
   ===== then build your service record in XLM
   uint32 uOPPRecHandle;
   char svcRecStr[] = 
      ""           // Service Class ID list
      "0x1105"                    // OPP
      "0x1101"      // SPP
      ""                 // Protocol Descriptor list
      "0x0100"       // L2CAP
      "0x0003"              // RFCOMM
      "5"      // Server Channel Number
      "John's OPP Server" // svc name
      ""                 // Profile Descriptor list
      "0x1105"              // OPP profile
      "0x0100  // profile version
   IBTServiceDiscovery_RegisterService (pMe->piBTSD, svcRecStr, TRUE);
   // see handling of SVC_REG_COMPLETE event above

   ===== To add the Supported Formats list to the OPP service record
   char str[] = 
      ""                 // OPP Supported Formats list
      "0x01"                        // VCard 2.1
      "0x04";         // ICal 2.0
   IBTServiceDiscovery_WriteRecord (pMe->piBTSD, uOPPRecHandle, &str);

   ===== To change the service name attribute of the OPP service record
   char str[] = 
      "Smith's OPP Server";
   IBTServiceDiscovery_WriteRecord (pMe->piBTSD, uOPPRecHandle, &str);

   ===== To deregister the service
   IBTServiceDiscovery_DeregisterService (pMe->piBTSD, uOPPRecHandle);

   ===== To find out what services are provided by the local device
   int nRecCount = 0;
   BTServiceRecordSummary* pSvcRecSummary = NULL;
   IBTServiceDiscovery_GetLocalDBSummary (pMe->piBTSD, NULL, 0, &nRecCount);
   pSvcRecSummary = MALLOC (nRecCount * sizeof(BTServiceRecordSummary));
   IBTServiceDiscovery_GetLocalDBSummary (pMe->piBTSD, pSvcRecSummary,
                                          nRecCount, &nRecCount);

   ===== To find FTP service record(s) in local database
   int i = nRecCount;
   while (i-- > 0)
      if (pSvcRecSummary[i]->profileUUID == AEEBT_SCU_OBEX_FILE_TRANSFER)
         char* recStr = NULL;
         IBTServiceDiscovery_ReadRecord (pMe->piBTSD, uOPPRecHandle,
                                         NULL, 0, &nSize);
         recStr = MALLOC (nSize);
         IBTServiceDiscovery_ReadRecord (pMe->piBTSD, uOPPRecHandle,
                                         recStr, nSize, &nSize);
         // app must parse recStr to get the attributes

         FREE (recStr);