static void records_cb(sdp_list_t *recs, int err, gpointer data) { struct pending_reply *pr = data; int len; sdp_data_t *d; sdp_record_t *rec = NULL; char name[MAX_NAME_SIZE], *desc = NULL; if (err < 0) { error_connection_attempt_failed(pr->conn, pr->msg, -err); goto fail; } if (!recs || !recs->data) { error_not_supported(pr->conn, pr->msg); error("Invalid PAN service record"); goto fail; } rec = recs->data; /* Concat remote name and service name */ memset(name, 0, MAX_NAME_SIZE); if (read_remote_name(&pr->src, &pr->dst, name, MAX_NAME_SIZE) < 0) len = 0; else len = strlen(name); d = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY); if (d) { snprintf(name + len, MAX_NAME_SIZE - len, len ? " (%.*s)" : "%.*s", d->unitSize, d->val.str); } /* Extract service description from record */ d = sdp_data_get(rec, SDP_ATTR_SVCDESC_PRIMARY); if (d) { desc = g_new0(char, d->unitSize); snprintf(desc, d->unitSize, "%.*s", d->unitSize, d->val.str); } sdp_list_free(recs, (sdp_free_func_t) sdp_record_free); if (connection_register(pr->path, &pr->src, &pr->dst, pr->id, name, desc) < 0) { error_failed(pr->conn, pr->msg, "D-Bus path registration failed"); goto fail; } connection_store(pr->path, FALSE); connection_paths = g_slist_append(connection_paths, g_strdup(pr->path)); create_path(pr->conn, pr->msg, pr->path, "ConnectionCreated"); fail: g_free(desc); pending_reply_free(pr); }
static int network_probe(struct btd_device *device, GSList *uuids, uint16_t id) { struct btd_adapter *adapter = device_get_adapter(device); const gchar *path = device_get_path(device); bdaddr_t src, dst; DBG("path %s", path); adapter_get_address(adapter, &src); device_get_address(device, &dst); return connection_register(device, path, &src, &dst, id); }
static void parse_stored_connection(char *key, char *value, void *data) { bdaddr_t dst, *src = data; char path[MAX_PATH_LENGTH]; char addr[18]; const char *ptr; char *name; int len, id; /* Format: XX:XX:XX:XX:XX:XX#{NAP, GN} name:description */ /* Parsing the key: address#role */ ptr = strchr(key, '#'); /* Empty address or invalid len */ if (!ptr || ((ptr - key) != 17)) return; memset(addr, 0, 18); strncpy(addr, key, 17); str2ba(addr, &dst); /* Empty role */ if (++ptr == NULL) return; if (strcasecmp("nap", ptr) == 0) id = BNEP_SVC_NAP; else if (strcasecmp("gn", ptr) == 0) id = BNEP_SVC_GN; else if (strcasecmp("panu", ptr) == 0) id = BNEP_SVC_PANU; else return; snprintf(path, MAX_PATH_LENGTH, NETWORK_PATH "/connection%d", net_uid++); /* Parsing the value: name and description */ ptr = strchr(value, ':'); /* Empty name */ if (!ptr) return; len = ptr-value; name = g_malloc0(len + 1); strncpy(name, value, len); /* Empty description */ if (++ptr == NULL) { g_free(name); return; } if (connection_register(path, src, &dst, id, name, ptr) == 0) { char *rpath = g_strdup(path); connection_paths = g_slist_append(connection_paths, rpath); } g_free(name); }