@@ -97,31 +97,29 @@ gboolean BluezEndpoint::BluezCharacteristicReadValue(BluezGattCharacteristic1 *
9797gboolean BluezEndpoint::BluezCharacteristicAcquireWrite (BluezGattCharacteristic1 * aChar, GDBusMethodInvocation * aInvocation,
9898 GUnixFDList * aFDList, GVariant * aOptions)
9999{
100- int fds[2 ] = { -1 , -1 };
101- #if CHIP_ERROR_LOGGING
102- char * errStr;
103- #endif // CHIP_ERROR_LOGGING
100+ int fds[2 ] = { -1 , -1 };
104101 BluezConnection * conn = nullptr ;
102+ const char * deviceObjectPath;
105103 uint16_t mtu;
106104
107- conn = GetBluezConnectionViaDevice ();
108105 VerifyOrReturnValue (
109- conn != nullptr , FALSE ,
110- g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.Failed" , " No CHIPoBLE connection" ));
111-
112- ChipLogDetail (DeviceLayer, " BluezCharacteristicAcquireWrite is called, conn: %p" , conn);
113-
106+ g_variant_lookup (aOptions, " device" , " &o" , &deviceObjectPath), FALSE ,
107+ ChipLogError (DeviceLayer, " FAIL: No device in options in %s" , __func__);
108+ g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.InvalidArguments" , " No device object path" ));
114109 VerifyOrReturnValue (
115110 g_variant_lookup (aOptions, " mtu" , " q" , &mtu), FALSE , ChipLogError (DeviceLayer, " FAIL: No MTU in options in %s" , __func__);
116- g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.InvalidArguments" , " MTU negotiation failed" ));
111+ g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.InvalidArguments" , " No MTU value" ));
112+
113+ conn = GetBluezConnection (deviceObjectPath);
114+ VerifyOrReturnValue (
115+ conn != nullptr , FALSE ,
116+ g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.Failed" , " No CHIPoBLE connection for the device" ));
117+
117118 conn->SetMTU (mtu);
118119
119120 if (socketpair (AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0 , fds) < 0 )
120121 {
121- #if CHIP_ERROR_LOGGING
122- errStr = strerror (errno);
123- #endif // CHIP_ERROR_LOGGING
124- ChipLogError (DeviceLayer, " FAIL: socketpair: %s in %s" , StringOrNullMarker (errStr), __func__);
122+ ChipLogError (DeviceLayer, " FAIL: socketpair: %s in %s" , StringOrNullMarker (strerror (errno)), __func__);
125123 g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.Failed" , " FD creation failed" );
126124 return FALSE ;
127125 }
@@ -148,40 +146,37 @@ static gboolean BluezCharacteristicAcquireWriteError(BluezGattCharacteristic1 *
148146gboolean BluezEndpoint::BluezCharacteristicAcquireNotify (BluezGattCharacteristic1 * aChar, GDBusMethodInvocation * aInvocation,
149147 GUnixFDList * aFDList, GVariant * aOptions)
150148{
151- int fds[2 ] = { -1 , -1 };
152- #if CHIP_ERROR_LOGGING
153- char * errStr;
154- #endif // CHIP_ERROR_LOGGING
149+ int fds[2 ] = { -1 , -1 };
155150 BluezConnection * conn = nullptr ;
156151 bool isAdditionalAdvertising = false ;
152+ const char * deviceObjectPath;
157153 uint16_t mtu;
158154
159155#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
160156 isAdditionalAdvertising = (aChar == mC3 .get ());
161157#endif
162158
163- if (bluez_gatt_characteristic1_get_notifying (aChar))
164- {
165- g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.NotPermitted" , " Already notifying" );
166- return FALSE ;
167- }
159+ VerifyOrReturnValue (
160+ !bluez_gatt_characteristic1_get_notifying (aChar), FALSE ,
161+ g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.NotPermitted" , " Already notifying" ));
162+ VerifyOrReturnValue (
163+ g_variant_lookup (aOptions, " device" , " &o" , &deviceObjectPath), FALSE ,
164+ ChipLogError (DeviceLayer, " FAIL: No device in options in %s" , __func__);
165+ g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.InvalidArguments" , " No device object path" ));
166+ VerifyOrReturnValue (
167+ g_variant_lookup (aOptions, " mtu" , " q" , &mtu), FALSE , ChipLogError (DeviceLayer, " FAIL: No MTU in options in %s" , __func__);
168+ g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.InvalidArguments" , " No MTU value" ));
168169
169- conn = GetBluezConnectionViaDevice ( );
170+ conn = GetBluezConnection (deviceObjectPath );
170171 VerifyOrReturnValue (
171172 conn != nullptr , FALSE ,
172- g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.Failed" , " No CHIPoBLE connection" ));
173+ g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.Failed" , " No CHIPoBLE connection for the device " ));
173174
174- VerifyOrReturnValue (
175- g_variant_lookup (aOptions, " mtu" , " q" , &mtu), FALSE , ChipLogError (DeviceLayer, " FAIL: No MTU in options in %s" , __func__);
176- g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.InvalidArguments" , " MTU negotiation failed" ););
177175 conn->SetMTU (mtu);
178176
179177 if (socketpair (AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0 , fds) < 0 )
180178 {
181- #if CHIP_ERROR_LOGGING
182- errStr = strerror (errno);
183- #endif // CHIP_ERROR_LOGGING
184- ChipLogError (DeviceLayer, " FAIL: socketpair: %s in %s" , StringOrNullMarker (errStr), __func__);
179+ ChipLogError (DeviceLayer, " FAIL: socketpair: %s in %s" , StringOrNullMarker (strerror (errno)), __func__);
185180 g_dbus_method_invocation_return_dbus_error (aInvocation, " org.bluez.Error.Failed" , " FD creation failed" );
186181 return FALSE ;
187182 }
@@ -208,10 +203,13 @@ static gboolean BluezCharacteristicAcquireNotifyError(BluezGattCharacteristic1 *
208203 return TRUE ;
209204}
210205
206+ // NOTE: When using with BlueZ >= 5.80, this method can be removed. Also, the GetBluezConnectionViaDevice
207+ // method will no longer be needed, since every callback will have the device object path available
208+ // in the options parameter.
211209gboolean BluezEndpoint::BluezCharacteristicConfirm (BluezGattCharacteristic1 * aChar, GDBusMethodInvocation * aInvocation)
212210{
213211 BluezConnection * conn = GetBluezConnectionViaDevice ();
214- ChipLogDetail (Ble , " Indication confirmation, %p" , conn);
212+ ChipLogDetail (DeviceLayer , " Indication confirmation: conn= %p" , conn);
215213 bluez_gatt_characteristic1_complete_confirm (aChar, aInvocation);
216214 BLEManagerImpl::HandleTXComplete (conn);
217215 return TRUE ;
0 commit comments