Changes

Line 329: Line 329:  
[12.0.0+] The Enable vfunc called above for Audio does the following:
 
[12.0.0+] The Enable vfunc called above for Audio does the following:
 
* Calls a func which does the following:
 
* Calls a func which does the following:
** Uses BSA to enable AV. Besides the callback, the only field in the passed struct which is set is <code>features</code>. This is set for "remote control target".
+
** Uses BSA to enable AV. Besides the callback, the only field in the passed struct which is set is <code>features</code>. This is ORRed to set bit0 for "remote control target", which with [13.0.0+] is only done if [[System_Settings|system-setting]] <code>bluetooth_debug!is_av_rc_tg</code> is set to true.
 
** Error handling + state setup is done.
 
** Error handling + state setup is done.
 
** Uses BSA to register AV twice, with the default input struct.
 
** Uses BSA to register AV twice, with the default input struct.
Line 795: Line 795:     
== ConnectGattServer ==
 
== ConnectGattServer ==
Takes an input u8, an [[#Address]], a bool, an [[Applet_Manager_services#AppletResourceUserId|AppletResourceUserId]], no output.
+
Takes an input u8 client_if, an [[#Address]], a bool, an [[Applet_Manager_services#AppletResourceUserId|AppletResourceUserId]], no output.
    
This is used by [[BTM_services|btm]].
 
This is used by [[BTM_services|btm]].
 +
 +
The input bool and AppletResourceUserId are unused.
 +
 +
The is_direct field passed to BSA is value 1.
    
== CancelConnectGattServer ==
 
== CancelConnectGattServer ==
Line 948: Line 952:  
== SetBleScanParameter ==
 
== SetBleScanParameter ==
 
Takes two input u16s, no output.
 
Takes two input u16s, no output.
 +
 +
The first u16 is scan_interval, the second u16 is scan_window.
    
This is used by [[BTM_services|btm]].
 
This is used by [[BTM_services|btm]].
Line 1,053: Line 1,059:  
== CloseAudioControlInput ==
 
== CloseAudioControlInput ==
 
Takes an input [[#Address]], no output.
 
Takes an input [[#Address]], no output.
 +
 +
This uses the BSA AV API to close the AVRCP connection.
    
== RegisterAudioControlNotification ==
 
== RegisterAudioControlNotification ==
 
Takes an input [[#Address]] and an u32 [[#AvrcEventType]], no output.
 
Takes an input [[#Address]] and an u32 [[#AvrcEventType]], no output.
 +
 +
This uses the BSA AV API to send a vendor control command: ctype=0x3, label={counter which is incremented}, length=0x9, data=[0x31, 0x00, 0x00, 0x05, {u8 [[#AvrcEventType]]}, {rest is zeros}].
 +
 +
This does nothing since BSA requires [[#EnableBluetooth|features]] bit1 and bit3 to be set in order to use this.
    
== SendAudioControlPassthroughCommand ==
 
== SendAudioControlPassthroughCommand ==
 
Takes an input [[#Address]], an u32 [[#AvrcOperationId]], an u32 [[#AvrcStateType]], no output.
 
Takes an input [[#Address]], an u32 [[#AvrcOperationId]], an u32 [[#AvrcStateType]], no output.
 +
 +
This uses the BSA AV API to send a remote control command: label={counter which is incremented}, rc_id=[[#AvrcOperationId]], key_state=[[#AvrcStateType]].
 +
 +
This does nothing since BSA requires [[#EnableBluetooth|features]] bit1 to be set in order to use this.
    
== SendAudioControlSetAbsoluteVolumeCommand ==
 
== SendAudioControlSetAbsoluteVolumeCommand ==
 
Takes an input [[#Address]] and a s32, no output.
 
Takes an input [[#Address]] and a s32, no output.
 +
 +
This uses the BSA AV API to send a vendor control command: ctype=0x0, label={counter which is incremented}, length=0x5, data=[0x50, 0x00, 0x00, 0x01, {input s32 value written as an u8}].
 +
 +
See [[#RegisterAudioControlNotification]] regarding the usage requirement.
    
== IsManufacturingMode ==
 
== IsManufacturingMode ==
Line 1,825: Line 1,845:  
= BleAdvertiseFilter =
 
= BleAdvertiseFilter =
 
This is "nn::bluetooth::BleAdvertiseFilter". This is a 0x3E-byte struct.
 
This is "nn::bluetooth::BleAdvertiseFilter". This is a 0x3E-byte struct.
  −
= BleAdvertisePacketParameter =
  −
This is "nn::bluetooth::BleAdvertisePacketParameter". This is a 8-byte struct with 1-byte alignment.
  −
  −
= BleScanResult =
  −
This is "nn::bluetooth::BleScanResult". This is a 0x148-byte struct.
      
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 1,838: Line 1,852:  
! Description
 
! Description
 
|-
 
|-
| 0x0 || 0x1 ||  
+
| 0x0 || 0x1 || FilterId
 +
|-
 +
| 0x1 || 0x1 || CondDataSize. Only used with CondType Manu.
 
|-
 
|-
| 0x1 || 0x6 || [[#Address]]
+
| 0x2 || 0x1 || CondType
 
|-
 
|-
| 0x7 || 0x139 ||  
+
| 0x3 || 0x1D || CondData, content depends on CondType.
 
|-
 
|-
| 0x140 || 0x4 || s32
+
| 0x20 || 0x1D || Mask. Only used with CondType Manu. +0 = u16 CompanyIdMask, then {pattern mask}.
 
|-
 
|-
| 0x144 || 0x4 || s32
+
| 0x3D || 0x1 || MaskSize. Only used with CondType Manu.
 
|}
 
|}
   −
= BleConnectionInfo =
+
CondType:
This is "nn::bluetooth::BleConnectionInfo". This is a 0xC-byte struct.
  −
 
   
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
! Offset
+
! Value
! Size
+
! Name
! Description
+
! Description
 
|-
 
|-
| 0x0 || 0x4 || ConnectionHandle, 0xFFFFFFFF ([5.0.0-5.0.2] 0xFFFF) is invalid.
+
| 2-3 || || ServiceUuid16. CondData = 16bit UUID which is byteswapped.
 
|-
 
|-
| 0x4 || 0x6 || [[#Address]]
+
| 4-5 || || ServiceUuid32. CondData = 32bit UUID which is byteswapped.
 
|-
 
|-
| 0xA || 0x2 || Padding
+
| 6-7 || || ServiceUuid128. CondData = 128bit UUID which is copied raw into the param struct.
 
|-
 
|-
 +
| 255 || || Manu. CondData: u16 CompanyId, then {pattern data}.
 
|}
 
|}
   −
= GattAttributeUuid =
+
To pass filtering, the BLE advert data should be: data & Mask == CondData (following the type field in the advert entry with the matching type).
This is "nn::bluetooth::GattAttributeUuid". This is a 0x14-byte struct with 4-byte alignment.
+
 
 +
= BleAdvertisePacketParameter =
 +
This is "nn::bluetooth::BleAdvertisePacketParameter". This is a 8-byte struct with 1-byte alignment.
 +
 
 +
[[BTM_services#StartBleScanForGeneral|StartBleScanForGeneral]] generates a [[#BleAdvertiseFilter]] from this. CondType = Manu, CondDataSize = 0xA. CondData: +0 = u16 CompanyId, u8 +2 = 0x1, +3 = {data copied from PatternData, then an u8 with value 0x0}. MaskSize = 0x9, Mask = {all 0xFF}.
 +
 
 +
[[BTM_services#StartBleScanForPaired|StartBleScanForPaired]] generates a [[#BleAdvertiseFilter]] from this, similar to the above. CondType = Manu, CondDataSize = 0x11. CondData: +0 = u16 CompanyId, u8 +2 = 0x1, +3 = {data copied from PatternData, then an u8 with value 0x0, then {6-byte system btaddr}}. MaskSize = 0x10, Mask = {all 0xFF except u8 +0x9 which is 0x0}.
    
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 1,875: Line 1,896:  
! Description
 
! Description
 
|-
 
|-
| 0x0 || 0x4 || UUID size, must be 0x2, 0x4, or 0x10.
+
| 0x0 || 0x2 || CompanyId
 
|-
 
|-
| 0x4 || 0x10 || UUID with the above size.
+
| 0x2 || 0x6 || PatternData
 
|}
 
|}
   −
= GattId =
+
= BleScanResult =
This is "nn::bluetooth::GattId". This is a 0x18-byte struct with 4-byte alignment.
+
This is "nn::bluetooth::BleScanResult". This is a 0x148-byte struct.
    
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 1,889: Line 1,910:  
! Description
 
! Description
 
|-
 
|-
| 0x0 || 0x1 || InstanceId
+
| 0x0 || 0x1 ||  
 +
|-
 +
| 0x1 || 0x6 || [[#Address]]
 +
|-
 +
| 0x7 || || Array of entries where each entry is 0x1F-bytes. hid compares +1 with 0xFF and +0x2 with the cached output from [[#BTM_services#GetBleScanParameterGeneral|GetBleScanParameterGeneral]] (entry+0x4 is skipped over).
 
|-
 
|-
| 0x1 || 0x3 || Padding
+
| 0x140 || 0x4 || s32 Total entries in the array at 0x8.
 
|-
 
|-
| 0x4 || 0x14 || [[#GattAttributeUuid]]
+
| 0x144 || 0x4 || s32
 
|}
 
|}
   −
= LeEventInfo =
+
= BleConnectionInfo =
This is a 0x400-byte struct.
+
This is "nn::bluetooth::BleConnectionInfo". This is a 0xC-byte struct.
    
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 1,905: Line 1,930:  
! Description
 
! Description
 
|-
 
|-
| 0x0 || 0x4 ||  
+
| 0x0 || 0x4 || ConnectionHandle, 0xFFFFFFFF ([5.0.0-5.0.2] 0xFFFF) is invalid.
 +
|-
 +
| 0x4 || 0x6 || [[#Address]]
 +
|-
 +
| 0xA || 0x2 || Padding
 +
|-
 +
|}
 +
 
 +
= GattAttributeUuid =
 +
This is "nn::bluetooth::GattAttributeUuid". This is a 0x14-byte struct with 4-byte alignment.
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
! Offset
 +
! Size
 +
! Description
 +
|-
 +
| 0x0 || 0x4 || [[#BleGattUuid]] size. Must be 0x2, 0x4, or 0x10.
 +
|-
 +
| 0x4 || 0x10 || [[#BleGattUuid]] with the above size.
 +
|}
 +
 
 +
= GattId =
 +
This is "nn::bluetooth::GattId". This is a 0x18-byte struct with 4-byte alignment.
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
! Offset
 +
! Size
 +
! Description
 +
|-
 +
| 0x0 || 0x1 || InstanceId
 +
|-
 +
| 0x1 || 0x3 || Padding
 +
|-
 +
| 0x4 || 0x14 || [[#GattAttributeUuid]]
 +
|}
 +
 
 +
= BleGattUuid =
 +
This is an enum of u16, u32 and u128 values.
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Value
 +
!  Description
 +
|-
 +
| 0x2902 || ClientConfigUuid16
 +
|-
 +
| 0x2908 || ReportReferenceUuid16
 +
|-
 +
| 0x1B666C080A578E83994EA7F7BF50DDA3 || PalmaOtafuControlPointUuid128
 +
|-
 +
| 0x26FE2EE709244FB7914061D97A6CE8A2 || PalmaOtafuDataUuid128
 +
|-
 +
| 0x45CEF889AF8E0784664404737C7FBE2B || NbatUuid128
 +
|-
 +
| 0x46CEF889AF8E0784664404737C7FBE2B || BatteryLevelUuid128
 +
|-
 +
| 0x47CEF889AF8E0784664404737C7FBE2B || BatteryStateUuid128
 +
|-
 +
| 0xD88B7646729DBDA17A4425F4101126C7 || PalmaOtafuUuid128
 +
|-
 +
| 0xE5237AE2516B55BB67456DF36CE17566 || NhogUuid128
 +
|-
 +
| 0xE6237AE2516B55BB67456DF36CE17566 || InputReportUuid128
 +
|-
 +
| 0xE7237AE2516B55BB67456DF36CE17566 || OutputCommandUuid128
 +
|-
 +
| 0xE8237AE2516B55BB67456DF36CE17566 || CommandResponseUuid128
 +
|}
 +
 
 +
= BleClientGattOperationStatus =
 +
This is an u8 enum. This is converted from the [[#LeEventInfo]] status field.
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Value
 +
!  Name
 +
!  Description
 +
|-
 +
| 0 || || Same as [[#LeEventInfo]] status 0.
 +
|-
 +
| 1 || || Same as [[#LeEventInfo]] status 55.
 +
|-
 +
| 2 || || Same as [[#LeEventInfo]] status 25, 52.
 +
|-
 +
| 3 || || Same as [[#LeEventInfo]] status 4, 16, 21, 50.
 +
|-
 +
| 4 || || Same as [[#LeEventInfo]] status 5.
 +
|-
 +
| 5 || || Same as [[#LeEventInfo]] status 6.
 +
|-
 +
| 6 || || Same as [[#LeEventInfo]] status 7.
 +
|-
 +
| 7 || || Same as [[#LeEventInfo]] status 9.
 +
|-
 +
| 8 || || Same as [[#LeEventInfo]] status 13.
 +
|-
 +
| 9 || || Used as the default case when the [[#LeEventInfo]] status is unrecognized.
 +
|-
 +
| 10 || || Same as [[#LeEventInfo]] status 35.
 +
|}
 +
 
 +
= LeEventInfo =
 +
This is a 0x400-byte struct.
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
! Offset
 +
! Size
 +
! Description
 +
|-
 +
| 0x0 || 0x4 || Status. 0 = success, non-zero = error.
 
|-
 
|-
| 0x4 || 0x4 ||  
+
| 0x4 || 0x4 || ConnectionId
 
|-
 
|-
| 0x8 || 0x1 ||  
+
| 0x8 || 0x1 || Flags. Bit0 = IsWrite, bit1 = IsDescriptor, bit2 = IsNotify.
 +
When bit2 is set, bit0 = IsIndication.
 
|-
 
|-
 
| 0x9 || 0x3 || Padding
 
| 0x9 || 0x3 || Padding
 
|-
 
|-
| 0xC || 0x14 || [[#GattAttributeUuid]]
+
| 0xC || 0x14 || Service [[#GattAttributeUuid]]
 
|-
 
|-
| 0x20 || 0x14 || [[#GattAttributeUuid]]
+
| 0x20 || 0x14 || Characteristic [[#GattAttributeUuid]]
 
|-
 
|-
| 0x34 || 0x14 || [[#GattAttributeUuid]]
+
| 0x34 || 0x14 || Descriptor [[#GattAttributeUuid]]
 
|-
 
|-
 
| 0x48 || 0x2 || Size of the below data.
 
| 0x48 || 0x2 || Size of the below data.
 
|-
 
|-
| 0x4A || {above size} || Data.
+
| 0x4A || 0x200 || Data with the above size.
 
|}
 
|}
   Line 1,933: Line 2,071:  
! Description
 
! Description
 
|-
 
|-
| 0x0 || 0x1 || Converted from [[#LeEventInfo]]+0x0.
+
| 0x0 || 0x1 || [[#BleClientGattOperationStatus]]
 
|-
 
|-
 
| 0x1 || 0x3 || Padding
 
| 0x1 || 0x3 || Padding
Line 2,035: Line 2,173:     
= AvrcOperationId =
 
= AvrcOperationId =
This is "nn::bluetooth::hal::AvrcOperationId".
+
This is "nn::bluetooth::hal::AvrcOperationId". This is the same as tBSA_AV_RC.
    
= AvrcStateType =
 
= AvrcStateType =
This is "nn::bluetooth::hal::AvrcStateType".
+
This is "nn::bluetooth::hal::AvrcStateType". This is the same as tBSA_AV_STATE.
    
= Notes =
 
= Notes =
Line 2,073: Line 2,211:  
Various btdrv service commands use a custom BSA extension (message-ids based at 0x8CA/2250), this is referred to as "robson". The following BSA modules are supported by the BSA server task thread (including the aforementioned robson): sys, dm, disc, sec, hh, [12.0.0+] av, dg, tm, ble.
 
Various btdrv service commands use a custom BSA extension (message-ids based at 0x8CA/2250), this is referred to as "robson". The following BSA modules are supported by the BSA server task thread (including the aforementioned robson): sys, dm, disc, sec, hh, [12.0.0+] av, dg, tm, ble.
   −
The following L2CAP services are registered (dynamic channels): SDP, ATT (GATT), RFCOMM, HID (PSMs: 0x11, 0x13, 0x8001, 0x8003), [12.0.0+] AVCTP/AVCTP_Browsing (active audio connection required), [12.0.0+] AVDTP.
+
The following L2CAP services are registered (dynamic channels): SDP, ATT (GATT), RFCOMM, HID (PSMs: 0x11, 0x13, 0x8001, 0x8003), [12.0.0+] AVCTP/AVCTP_Browsing (only when the features bitfield passed to BSA_AvEnable by [[#EnableBluetooth]] has bit0 ("remote control target") or bit1 set), [12.0.0+] AVDTP.
    
<code>l2cu_send_peer_echo_rsp</code> is called with p_data=NULL and data_len=0, therefore no data is returned in the L2CAP ECHO response.
 
<code>l2cu_send_peer_echo_rsp</code> is called with p_data=NULL and data_len=0, therefore no data is returned in the L2CAP ECHO response.