In Initiator mode, this is when we get a DEP_LINK_UP event.
In target mode, DEP link is up as soon as we see a new device.
This fix avoids racy situations where a Device interface is available
although the DEP link is still not up.
} else {
if (adapter->dep_timer > 0)
g_source_remove(adapter->dep_timer);
+
+ if (!__near_device_register_interface(adapter->device_link))
+ return -ENODEV;
}
return 0;
struct near_device *device;
int err;
+ DBG();
+
device = __near_device_add(adapter->idx, target_idx, nfcid, nfcid_len);
if (!device)
return -ENODEV;
adapter->device_link = device;
- if (adapter->dep_up)
+ if (adapter->dep_up) {
+ if (!__near_device_register_interface(device))
+ return -ENODEV;
+
return 0;
+ }
err = __near_netlink_dep_link_up(adapter->idx, target_idx,
NFC_COMM_ACTIVE, NFC_RF_INITIATOR);
g_hash_table_insert(device_hash, path, device);
+ return device;
+}
+
+bool __near_device_register_interface(struct near_device *device)
+{
DBG("connection %p", connection);
- g_dbus_register_interface(connection, device->path,
- NFC_DEVICE_INTERFACE,
- device_methods, NULL, NULL,
+ return g_dbus_register_interface(connection, device->path,
+ NFC_DEVICE_INTERFACE,
+ device_methods, NULL, NULL,
device, NULL);
-
- return device;
}
int __near_device_listen(struct near_device *device, near_device_io_cb cb)
struct near_device *__near_device_add(uint32_t idx, uint32_t target_idx,
uint8_t *nfcid, uint8_t nfcid_len);
void __near_device_remove(struct near_device *device);
+bool __near_device_register_interface(struct near_device *device);
int __near_device_listen(struct near_device *device, near_device_io_cb cb);
int __near_device_push(struct near_device *device,
struct near_ndef_message *ndef, char *service_name,