コード例 #1
0
ファイル: bluetooth_legacy.c プロジェクト: manjurajv/connman
static gboolean adapter_added(DBusConnection *conn, DBusMessage *message,
				void *user_data)
{
	const char *path;

	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
				DBUS_TYPE_INVALID);
	add_adapter(conn, path);
	return TRUE;
}
コード例 #2
0
ファイル: wiiusb_hid.c プロジェクト: jimmy906/RetroArch
static void *wiiusb_hid_init(void)
{
   unsigned i;
   u8 count;
   int ret;
   usb_device_entry *dev_entries;
   wiiusb_hid_t *hid = (wiiusb_hid_t*)calloc(1, sizeof(*hid));

   (void)ret;

   if (!hid)
      goto error;

   hid->slots = pad_connection_init(MAX_USERS);

   if (!hid->slots)
      goto error;

   dev_entries = (usb_device_entry *)calloc(MAX_USERS, sizeof(*dev_entries));

   if (!dev_entries)
      goto error;

   USB_Initialize();

   if (USB_GetDeviceList(dev_entries, MAX_USERS, USB_CLASS_HID, &count) < 0)
   {
      free(dev_entries);
      goto error;
   }

   for (i = 0; i < count; i++)
   {
      if (dev_entries[i].vid > 0 && dev_entries[i].pid > 0)
         add_adapter(hid, &dev_entries[i]);
   }

   free(dev_entries);

   USB_DeviceChangeNotifyAsync(USB_CLASS_HID, wiiusb_hid_changenotify_cb, (void *)hid);

   return hid;

error:
   wiiusb_hid_free(hid);
   return NULL;
}
コード例 #3
0
static int libusb_hid_hotplug_callback(struct libusb_context *ctx,
      struct libusb_device *dev, libusb_hotplug_event event, void *user_data)
{
   libusb_hid_t *hid = (libusb_hid_t*)user_data;

   switch (event)
   {
      case LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED:
         add_adapter(hid, dev);
         break;
      case LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT:
         remove_adapter(hid, dev);
         break;
      default:
         RARCH_WARN("Unhandled event: %d\n", event);
         break;
   }

   return 0;
}
コード例 #4
0
ファイル: bluetooth_legacy.c プロジェクト: manjurajv/connman
static void list_adapters_reply(DBusPendingCall *call, void *user_data)
{
	DBusMessage *reply;
	DBusError error;
	char **adapters;
	int i, num_adapters;

	DBG("");

	reply = dbus_pending_call_steal_reply(call);

	dbus_error_init(&error);

	if (dbus_set_error_from_message(&error, reply) == TRUE) {
		connman_error("%s", error.message);
		dbus_error_free(&error);
		goto done;
	}

	if (dbus_message_get_args(reply, &error,
				DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH,
						&adapters, &num_adapters,
						DBUS_TYPE_INVALID) == FALSE) {
		if (dbus_error_is_set(&error) == TRUE) {
			connman_error("%s", error.message);
			dbus_error_free(&error);
		} else
			connman_error("Wrong arguments for adapter list");
		goto done;
	}

	for (i = 0; i < num_adapters; i++)
		add_adapter(connection, adapters[i]);

	g_strfreev(adapters);

done:
	dbus_message_unref(reply);

	dbus_pending_call_unref(call);
}
コード例 #5
0
ファイル: bluetooth_legacy.c プロジェクト: manjurajv/connman
static void powered_reply(DBusPendingCall *call, void *user_data)
{
	DBusError error;
	DBusMessage *reply;

	DBG("");

	reply = dbus_pending_call_steal_reply(call);

	dbus_error_init(&error);

	if (dbus_set_error_from_message(&error, reply) == TRUE) {
		connman_error("%s", error.message);
		dbus_error_free(&error);
		dbus_message_unref(reply);
		dbus_pending_call_unref(call);
		return;
	}

	dbus_message_unref(reply);
	dbus_pending_call_unref(call);

	add_adapter(connection, user_data);
}
コード例 #6
0
static void *libusb_hid_init(void)
{
   unsigned i, count;
   int ret;
   struct libusb_device **devices;
   libusb_hid_t *hid = (libusb_hid_t*)calloc(1, sizeof(*hid));

   if (!hid)
      goto error;

   ret = libusb_init(&hid->ctx);

   if (ret < 0)
      goto error;

   if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG))
      goto error;

   hid->slots = pad_connection_init(MAX_USERS);

   if (!hid->slots)
      goto error;

   count = libusb_get_device_list(hid->ctx, &devices);

   for (i = 0; i < count; i++)
   {
      struct libusb_device_descriptor desc;
      libusb_get_device_descriptor(devices[i], &desc);

      if (desc.idVendor > 0 && desc.idProduct > 0)
         add_adapter(hid, devices[i]);
   }

   if (count > 0)
      libusb_free_device_list(devices, 1);

   ret = libusb_hotplug_register_callback(
         hid->ctx,
         (libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
         LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT),
         (libusb_hotplug_flag)LIBUSB_HOTPLUG_ENUMERATE,
         LIBUSB_HOTPLUG_MATCH_ANY,
         LIBUSB_HOTPLUG_MATCH_ANY,
         LIBUSB_HOTPLUG_MATCH_ANY,
         libusb_hid_hotplug_callback,
         hid,
         &hid->hp);

   if (ret != LIBUSB_SUCCESS)
   {
      RARCH_ERR("Error creating a hotplug callback.\n");
      goto error;
   }

   hid->poll_thread = sthread_create(poll_thread, hid);

   if (!hid->poll_thread)
   {
      RARCH_ERR("Error creating polling thread");
      goto error;
   }

   return hid;

error:
   if (hid)
      libusb_hid_free(hid);
   return NULL;
}
コード例 #7
0
ファイル: plugin_bluez.c プロジェクト: DBattisti/antidote
/**
 * Connect adapter and devices D-Bus signals
 */
static void connect_adapter(const char *adapter)
{
	/* Find devices and connect to ChannelConnected/Destroyed signals */

	DBusGProxy *proxy;
	GHashTable *props;
	GValue *devlist;
	GError *error = NULL;
	GPtrArray *array;
	unsigned int i;

	DEBUG("connecting adapter: %s", adapter);

	proxy = dbus_g_proxy_new_for_name(conn, "org.bluez",
					  adapter, "org.bluez.Adapter");

	if (!proxy) {
		ERROR("Adapter interface not found");
		return;
	}

	add_adapter(adapter, proxy);

	dbus_g_proxy_add_signal(proxy, "DeviceCreated",
				DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);

	dbus_g_proxy_add_signal(proxy, "DeviceRemoved",
				DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);

	dbus_g_proxy_connect_signal(proxy, "DeviceCreated",
				    G_CALLBACK(device_created),
				    NULL, NULL);

	dbus_g_proxy_connect_signal(proxy, "DeviceRemoved",
				    G_CALLBACK(device_removed),
				    NULL, NULL);

	if (!dbus_g_proxy_call(proxy, "GetProperties", &error,
			       G_TYPE_INVALID,
			       dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
			       &props, G_TYPE_INVALID)) {
		if (error) {
			ERROR("Can't get device list: %s", error->message);
			g_error_free(error);
		} else {
			ERROR("Can't get device list, probably disconnected");
		}

		return;
	}

	DEBUG("Getting known devices list");

	devlist = g_hash_table_lookup(props, "Devices");

	if (devlist) {
		array = g_value_get_boxed(devlist);

		if (array)
			for (i = 0; i < array->len; ++i)
				connect_device_signals(g_ptr_array_index(array, i),
						       adapter);
	} else {
		DEBUG("No Devices property in adapter properties");
	}

	g_hash_table_destroy(props);
}
コード例 #8
0
ファイル: cxgb_tom.c プロジェクト: AhmadTux/freebsd
int
cxgb_offload_activate(struct adapter *adapter)
{
	struct t3cdev *dev = &adapter->tdev;
	int natids, err;
	struct t3c_data *t;
	struct tid_range stid_range, tid_range;
	struct mtutab mtutab;
	unsigned int l2t_capacity;

	t = malloc(sizeof(*t), M_CXGB, M_NOWAIT|M_ZERO);
	if (!t)
		return (ENOMEM);
	dev->adapter = adapter;

	err = (EOPNOTSUPP);
	if (dev->ctl(dev, GET_TX_MAX_CHUNK, &t->tx_max_chunk) < 0 ||
	    dev->ctl(dev, GET_MAX_OUTSTANDING_WR, &t->max_wrs) < 0 ||
	    dev->ctl(dev, GET_L2T_CAPACITY, &l2t_capacity) < 0 ||
	    dev->ctl(dev, GET_MTUS, &mtutab) < 0 ||
	    dev->ctl(dev, GET_TID_RANGE, &tid_range) < 0 ||
	    dev->ctl(dev, GET_STID_RANGE, &stid_range) < 0) {
		device_printf(adapter->dev, "%s: dev->ctl check failed\n", __FUNCTION__);
		goto out_free;
	}
      
	err = (ENOMEM);
	L2DATA(dev) = t3_init_l2t(l2t_capacity);
	if (!L2DATA(dev)) {
		device_printf(adapter->dev, "%s: t3_init_l2t failed\n", __FUNCTION__);
		goto out_free;
	}
	natids = min(tid_range.num / 2, MAX_ATIDS);
	err = init_tid_tabs(&t->tid_maps, tid_range.num, natids,
			    stid_range.num, ATID_BASE, stid_range.base);
	if (err) {	
		device_printf(adapter->dev, "%s: init_tid_tabs failed\n", __FUNCTION__);
		goto out_free_l2t;
	}
	
	t->mtus = mtutab.mtus;
	t->nmtus = mtutab.size;

	TASK_INIT(&t->tid_release_task, 0 /* XXX? */, t3_process_tid_release_list, dev);
	mtx_init(&t->tid_release_lock, "tid release", NULL, MTX_DUPOK|MTX_DEF);
	t->dev = dev;

	T3C_DATA (dev) = t;
	dev->recv = process_rx;
	dev->arp_update = t3_l2t_update;
	/* Register netevent handler once */
	if (TAILQ_EMPTY(&adapter_list)) {
#if defined(CONFIG_CHELSIO_T3_MODULE)
		if (prepare_arp_with_t3core())
			log(LOG_ERR, "Unable to set offload capabilities\n");
#endif
	}
	CTR1(KTR_CXGB, "adding adapter %p", adapter); 
	add_adapter(adapter);
	device_printf(adapter->dev, "offload started\n");
	adapter->flags |= CXGB_OFLD_INIT;
	return (0);

out_free_l2t:
	t3_free_l2t(L2DATA(dev));
	L2DATA(dev) = NULL;
out_free:
	free(t, M_CXGB);
	return (err);
}