Android BluetoothClass Major Service Classes, Minor and Major Device Classes

By default, the currently limited (2011) Android Bluetooth SDK, only offers access to the Major Class value of any given Bluetooth device (API getMajorDeviceClass() ), while the Minor class is only returned as a combination with the Major class (API getDeviceClass() ).

For a given Bluetooth Device (BluetoothDevice device;), one can get the Major Bluetooth class like this:

  1.  
  2. int deviceBTMajorClass = device.getBluetoothClass().getMajorDeviceClass();
  3.  

Then this integer variable can be used to determine the type of the device used:

  1.  
  2. private String getBTMajorDeviceClass(int major){
  3. switch(major){
  4. case BluetoothClass.Device.Major.AUDIO_VIDEO: return "AUDIO_VIDEO";
  5. case BluetoothClass.Device.Major.COMPUTER: return "COMPUTER";
  6. case BluetoothClass.Device.Major.HEALTH: return "HEALTH";
  7. case BluetoothClass.Device.Major.IMAGING: return "IMAGING";
  8. case BluetoothClass.Device.Major.MISC: return "MISC";
  9. case BluetoothClass.Device.Major.NETWORKING: return "NETWORKING";
  10. case BluetoothClass.Device.Major.PERIPHERAL: return "PERIPHERAL";
  11. case BluetoothClass.Device.Major.PHONE: return "PHONE";
  12. case BluetoothClass.Device.Major.TOY: return "TOY";
  13. case BluetoothClass.Device.Major.UNCATEGORIZED: return "UNCATEGORIZED";
  14. case BluetoothClass.Device.Major.WEARABLE: return "AUDIO_VIDEO";
  15. default: return "unknown!";
  16. }
  17. }
  18.  

The Bluetooth class (format type 00) is defined as a 3 Octet Integer. Please open the specifications here:
cod_definition

The Android SDK getMajorDeviceClass() API returns an integer corresponding to bits 12-11-10-9-8.
The getDeviceClass() API returns all the lower 12bits, as an integer corresponding to 12-11-10-9-8-7-6-5-4-3-2-1 .

Here are a few examples:
Bluetooth Device: Plantronics 590 A2DP Bluetooth Headset
getMajorDeviceClass: 1024
getDeviceClass:1028
Bits: (octet 3 missing) - (0 0 0 0 0 1 0 0) - (0 0 0 0 0 1 0 0)
Looking in the cod_definition.pdf attached above, on page 3, you will see that octet 2 indicates the Major Class Audio Video, and for the Audio Video Major Class, the Minor class (0 0 0 0 0 1) indicates a "Wearable Headset Device" (page 5).

Bluetooth Device: BeeWi BBK200 Mini Bluetooth Keyboard
getMajorDeviceClass: 1280
getDeviceClass:1344
Bits: (octet 3 missing) - (0 0 1 0 0 1 0 1) - (0 1 0 0 0 0 0 0)
Major class, (0 0 1 0 1) indicates Peripheral, and the Minor class (0 1) indicates a "Keyboard" (page 5, bottom).

To extract the minor class , you will need to take into account which major class was defined, because depending on the Major class, the minor class has a variable width. For Major class "Audio Video" the minor class was defined in bits 7->2, while for Major class "Peripheral", the minor class uses only two bits, 7->6.

You will need to write several functions like: GetAudioVideoMinorClass, GetPeripheralMinorClass and so on. One would look like:

  1.  
  2. int GetAudioVideoMinorClass(int cod) {
  3. return (cod & 0xFF) >> 2; // we only want the last 8 bits, then we shift to the right to only get the first 6
  4. }
  5.  

The Bluetooth COD specs also define a "Bluetooth Major service class". This one should be defined in OCTET 3, but Android's limited SDK only returns the Major device class and Minor device class (octet 2) and (octet 1).
Surprisingly, the info we need is there:

  1.  
  2. device.getBluetoothClass().toString()
  3.  

Contains all the three octets. For Plantronics 590, the string is: 0x240404 (it's hex). Changing that into binary shows:
00100100 00000100 00000100
Page 2 in Bluetooth cod specs, indicates bit 21 is "21 Audio (Speaker, Microphone, Headset service, ...)".
This bluetooth device also has bit 18 set, meaning Rendering (Printing, Speaker, ...) .

Related Post

This article has 2 Comments

  1. Thank you for post, it was very helpful for me!!!
    P.S. Do you have any ideas how to detect docked keyboard (it think it is usb, not through bluetooth)?

    Thank you.

  2. Hi Alex,

    It’s been a while since I looked into this, but for USB the HID classes should work the same. Just connect your device, and see how to read it’s class. Next part is straight forward .

Leave a Reply