static int btsco_match(device_t self, cfdata_t cfdata, void *aux) { prop_dictionary_t dict = aux; prop_object_t obj; obj = prop_dictionary_get(dict, BTDEVservice); if (prop_string_equals_cstring(obj, "HSET")) return 1; if (prop_string_equals_cstring(obj, "HF")) return 1; return 0; }
/* * Translate command sent from libdevmapper to func. */ static int dm_cmd_to_fun(prop_dictionary_t dm_dict) { int i, r; prop_string_t command; r = 0; if ((command = prop_dictionary_get(dm_dict, DM_IOCTL_COMMAND)) == NULL) return EINVAL; for(i = 0; cmd_fn[i].cmd != NULL; i++) if (prop_string_equals_cstring(command, cmd_fn[i].cmd)) break; if (!cmd_fn[i].allowed && (r = kauth_authorize_system(kauth_cred_get(), KAUTH_SYSTEM_DEVMAPPER, 0, NULL, NULL, NULL)) != 0) return r; if (cmd_fn[i].cmd == NULL) return EINVAL; aprint_debug("ioctl %s called\n", cmd_fn[i].cmd); r = cmd_fn[i].fn(dm_dict); return r; }
static int bthidev_match(device_t self, struct cfdata *cfdata, void *aux) { prop_dictionary_t dict = aux; prop_object_t obj; obj = prop_dictionary_get(dict, BTDEVservice); if (prop_string_equals_cstring(obj, "HID")) return 1; return 0; }
/* * Translate command sent from libdevmapper to func. */ static int dm_cmd_to_fun(prop_dictionary_t dm_dict){ int i, r; prop_string_t command; r = 0; if ((command = prop_dictionary_get(dm_dict, DM_IOCTL_COMMAND)) == NULL) return EINVAL; for(i = 0; cmd_fn[i].cmd != NULL; i++) if (prop_string_equals_cstring(command, cmd_fn[i].cmd)) break; if (cmd_fn[i].cmd == NULL) return EINVAL; aprint_debug("ioctl %s called\n", cmd_fn[i].cmd); r = cmd_fn[i].fn(dm_dict); return r; }
static void bthidev_attach(device_t parent, device_t self, void *aux) { struct bthidev_softc *sc = device_private(self); prop_dictionary_t dict = aux; prop_object_t obj; device_t dev; struct bthidev_attach_args bha; struct bthidev *hidev; struct hid_data *d; struct hid_item h; const void *desc; int locs[BTHIDBUSCF_NLOCS]; int maxid, rep, dlen; /* * Init softc */ sc->sc_dev = self; LIST_INIT(&sc->sc_list); callout_init(&sc->sc_reconnect, 0); callout_setfunc(&sc->sc_reconnect, bthidev_timeout, sc); sc->sc_state = BTHID_CLOSED; sc->sc_flags = BTHID_CONNECTING; sc->sc_ctlpsm = L2CAP_PSM_HID_CNTL; sc->sc_intpsm = L2CAP_PSM_HID_INTR; sockopt_init(&sc->sc_mode, BTPROTO_L2CAP, SO_L2CAP_LM, 0); /* * extract config from proplist */ obj = prop_dictionary_get(dict, BTDEVladdr); bdaddr_copy(&sc->sc_laddr, prop_data_data_nocopy(obj)); obj = prop_dictionary_get(dict, BTDEVraddr); bdaddr_copy(&sc->sc_raddr, prop_data_data_nocopy(obj)); obj = prop_dictionary_get(dict, BTDEVmode); if (prop_object_type(obj) == PROP_TYPE_STRING) { if (prop_string_equals_cstring(obj, BTDEVauth)) sockopt_setint(&sc->sc_mode, L2CAP_LM_AUTH); else if (prop_string_equals_cstring(obj, BTDEVencrypt)) sockopt_setint(&sc->sc_mode, L2CAP_LM_ENCRYPT); else if (prop_string_equals_cstring(obj, BTDEVsecure)) sockopt_setint(&sc->sc_mode, L2CAP_LM_SECURE); else { aprint_error(" unknown %s\n", BTDEVmode); return; } aprint_verbose(" %s %s", BTDEVmode, prop_string_cstring_nocopy(obj)); } obj = prop_dictionary_get(dict, BTHIDEVcontrolpsm); if (prop_object_type(obj) == PROP_TYPE_NUMBER) { sc->sc_ctlpsm = prop_number_integer_value(obj); if (L2CAP_PSM_INVALID(sc->sc_ctlpsm)) { aprint_error(" invalid %s\n", BTHIDEVcontrolpsm); return; } } obj = prop_dictionary_get(dict, BTHIDEVinterruptpsm); if (prop_object_type(obj) == PROP_TYPE_NUMBER) { sc->sc_intpsm = prop_number_integer_value(obj); if (L2CAP_PSM_INVALID(sc->sc_intpsm)) { aprint_error(" invalid %s\n", BTHIDEVinterruptpsm); return; } } obj = prop_dictionary_get(dict, BTHIDEVdescriptor); if (prop_object_type(obj) == PROP_TYPE_DATA) { dlen = prop_data_size(obj); desc = prop_data_data_nocopy(obj); } else { aprint_error(" no %s\n", BTHIDEVdescriptor); return; } obj = prop_dictionary_get(dict, BTHIDEVreconnect); if (prop_object_type(obj) == PROP_TYPE_BOOL && !prop_bool_true(obj)) sc->sc_flags |= BTHID_RECONNECT; /* * Parse the descriptor and attach child devices, one per report. */ maxid = -1; h.report_ID = 0; d = hid_start_parse(desc, dlen, hid_none); while (hid_get_item(d, &h)) { if (h.report_ID > maxid) maxid = h.report_ID; } hid_end_parse(d); if (maxid < 0) { aprint_error(" no reports found\n"); return; } aprint_normal("\n"); for (rep = 0 ; rep <= maxid ; rep++) { if (hid_report_size(desc, dlen, hid_feature, rep) == 0 && hid_report_size(desc, dlen, hid_input, rep) == 0 && hid_report_size(desc, dlen, hid_output, rep) == 0) continue; bha.ba_desc = desc; bha.ba_dlen = dlen; bha.ba_input = bthidev_null; bha.ba_feature = bthidev_null; bha.ba_output = bthidev_output; bha.ba_id = rep; locs[BTHIDBUSCF_REPORTID] = rep; dev = config_found_sm_loc(self, "bthidbus", locs, &bha, bthidev_print, config_stdsubmatch); if (dev != NULL) { hidev = device_private(dev); hidev->sc_dev = dev; hidev->sc_parent = self; hidev->sc_id = rep; hidev->sc_input = bha.ba_input; hidev->sc_feature = bha.ba_feature; LIST_INSERT_HEAD(&sc->sc_list, hidev, sc_next); } } /* * start bluetooth connections */ mutex_enter(bt_lock); if ((sc->sc_flags & BTHID_RECONNECT) == 0) bthidev_listen(sc); if (sc->sc_flags & BTHID_CONNECTING) bthidev_connect(sc); mutex_exit(bt_lock); }
static void btsco_attach(device_t parent, device_t self, void *aux) { struct btsco_softc *sc = device_private(self); prop_dictionary_t dict = aux; prop_object_t obj; /* * Init softc */ sc->sc_vgs = 200; sc->sc_vgm = 200; sc->sc_state = BTSCO_CLOSED; sc->sc_name = device_xname(self); cv_init(&sc->sc_connect, "connect"); mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_NONE); /* * copy in our configuration info */ obj = prop_dictionary_get(dict, BTDEVladdr); bdaddr_copy(&sc->sc_laddr, prop_data_data_nocopy(obj)); obj = prop_dictionary_get(dict, BTDEVraddr); bdaddr_copy(&sc->sc_raddr, prop_data_data_nocopy(obj)); obj = prop_dictionary_get(dict, BTDEVservice); if (prop_string_equals_cstring(obj, "HF")) { sc->sc_flags |= BTSCO_LISTEN; aprint_verbose(" listen mode"); } obj = prop_dictionary_get(dict, BTSCOchannel); if (prop_object_type(obj) != PROP_TYPE_NUMBER || prop_number_integer_value(obj) < RFCOMM_CHANNEL_MIN || prop_number_integer_value(obj) > RFCOMM_CHANNEL_MAX) { aprint_error(" invalid %s", BTSCOchannel); return; } sc->sc_channel = prop_number_integer_value(obj); aprint_verbose(" channel %d", sc->sc_channel); aprint_normal("\n"); DPRINTF("sc=%p\n", sc); /* * set up transmit interrupt */ sc->sc_intr = softint_establish(SOFTINT_NET, btsco_intr, sc); if (sc->sc_intr == NULL) { aprint_error_dev(self, "softint_establish failed\n"); return; } /* * attach audio device */ sc->sc_audio = audio_attach_mi(&btsco_if, sc, self); if (sc->sc_audio == NULL) { aprint_error_dev(self, "audio_attach_mi failed\n"); return; } pmf_device_register(self, NULL, NULL); }