?? avinfo.c
字號(hào):
printf("\n\t\tPayload Format: "); if (mpeg->mpf) printf("RFC-2250 RFC-3119\n"); else printf("RFC-2250\n");}static void print_sbc(struct sbc_codec_cap *sbc){ printf("\tMedia Codec: SBC\n\t\tChannel Modes: "); if (sbc->channel_mode & SBC_CHANNEL_MODE_MONO) printf("Mono "); if (sbc->channel_mode & SBC_CHANNEL_MODE_DUAL_CHANNEL) printf("DualChannel "); if (sbc->channel_mode & SBC_CHANNEL_MODE_STEREO) printf("Stereo "); if (sbc->channel_mode & SBC_CHANNEL_MODE_JOINT_STEREO) printf("JointStereo"); printf("\n\t\tFrequencies: "); if (sbc->frequency & SBC_SAMPLING_FREQ_16000) printf("16Khz "); if (sbc->frequency & SBC_SAMPLING_FREQ_32000) printf("32Khz "); if (sbc->frequency & SBC_SAMPLING_FREQ_44100) printf("44.1Khz "); if (sbc->frequency & SBC_SAMPLING_FREQ_48000) printf("48Khz "); printf("\n\t\tSubbands: "); if (sbc->allocation_method & SBC_SUBBANDS_4) printf("4 "); if (sbc->allocation_method & SBC_SUBBANDS_8) printf("8"); printf("\n\t\tBlocks: "); if (sbc->block_length & SBC_BLOCK_LENGTH_4) printf("4 "); if (sbc->block_length & SBC_BLOCK_LENGTH_8) printf("8 "); if (sbc->block_length & SBC_BLOCK_LENGTH_12) printf("12 "); if (sbc->block_length & SBC_BLOCK_LENGTH_16) printf("16 "); printf("\n\t\tBitpool Range: %d-%d\n", sbc->min_bitpool, sbc->max_bitpool);}static void print_media_codec(struct avdtp_media_codec_capability *cap){ switch (cap->media_codec_type) { case A2DP_CODEC_SBC: print_sbc((void *) cap); break; case A2DP_CODEC_MPEG12: print_mpeg12((void *) cap); break; default: printf("\tMedia Codec: Unknown\n"); }}static void print_caps(void *data, int size){ int processed; for (processed = 0; processed + 2 < size;) { struct avdtp_service_capability *cap; cap = data; if (processed + 2 + cap->length > size) { printf("Invalid capability data in getcap resp\n"); break; } switch (cap->category) { case AVDTP_MEDIA_TRANSPORT: case AVDTP_REPORTING: case AVDTP_RECOVERY: case AVDTP_CONTENT_PROTECTION: case AVDTP_MULTIPLEXING: /* FIXME: Add proper functions */ break; case AVDTP_MEDIA_CODEC: print_media_codec((void *) cap->data); break; } processed += 2 + cap->length; data += 2 + cap->length; }}static void init_request(struct avdtp_header *header, int request_id){ static int transaction = 0; header->packet_type = AVDTP_PKT_TYPE_SINGLE; header->message_type = AVDTP_MSG_TYPE_COMMAND; header->transaction = transaction; header->signal_id = request_id; /* clear rfa bits */ header->rfa0 = 0; transaction = (transaction + 1) % 16;}static int avdtp_send(int sk, void *data, int len){ int ret; ret = send(sk, data, len, 0); if (ret < 0) ret = -errno; else if (ret != len) ret = -EIO; if (ret < 0) { printf("Unable to send message: %s (%d)\n", strerror(-ret), -ret); return ret; } return ret;}static int avdtp_receive(int sk, void *data, int len){ int ret; ret = recv(sk, data, len, 0); if (ret < 0) { printf("Unable to receive message: %s (%d)\n", strerror(errno), errno); return -errno; } return ret;}int avdtp_get_caps(int sk, int seid){ struct seid_req req; char buffer[1024]; struct getcap_resp *caps = (void *) buffer; int ret; memset(&req, 0, sizeof(req)); init_request(&req.header, AVDTP_GET_CAPABILITIES); req.acp_seid = seid; ret = avdtp_send(sk, &req, sizeof(req)); if (ret < 0) return ret; memset(&buffer, 0, sizeof(buffer)); ret = avdtp_receive(sk, caps, sizeof(buffer)); if (ret < 0) return ret; if (ret < (sizeof(struct getcap_resp) + 4 + sizeof(struct avdtp_media_codec_capability))) { printf("Invalid capabilities\n"); return -1; } print_caps(caps, ret); return 0;}int avdtp_discover(int sk){ struct avdtp_header req; char buffer[256]; struct discover_resp *discover = (void *) buffer; int ret, seps, i; memset(&req, 0, sizeof(req)); init_request(&req, AVDTP_DISCOVER); ret = avdtp_send(sk, &req, sizeof(req)); if (ret < 0) return ret; memset(&buffer, 0, sizeof(buffer)); ret = avdtp_receive(sk, discover, sizeof(buffer)); if (ret < 0) return ret; seps = (ret - sizeof(struct avdtp_header)) / sizeof(struct seid_info); for (i = 0; i < seps; i++) { const char *type, *media; switch (discover->seps[i].type) { case AVDTP_SEP_TYPE_SOURCE: type = "Source"; break; case AVDTP_SEP_TYPE_SINK: type = "Sink"; break; default: type = "Invalid"; } switch (discover->seps[i].media_type) { case AVDTP_MEDIA_TYPE_AUDIO: media = "Audio"; break; case AVDTP_MEDIA_TYPE_VIDEO: media = "Video"; break; case AVDTP_MEDIA_TYPE_MULTIMEDIA: media = "Multimedia"; break; default: media = "Invalid"; } printf("Stream End-Point #%d: %s %s %s\n", discover->seps[i].seid, media, type, discover->seps[i].inuse ? "*" : ""); avdtp_get_caps(sk, discover->seps[i].seid); } return 0;}static int l2cap_connect(bdaddr_t *src, bdaddr_t *dst){ struct sockaddr_l2 l2a; int sk; memset(&l2a, 0, sizeof(l2a)); l2a.l2_family = AF_BLUETOOTH; bacpy(&l2a.l2_bdaddr, src); sk = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); if (sk < 0) { printf("Cannot create L2CAP socket. %s(%d)\n", strerror(errno), errno); return -errno; } if (bind(sk, (struct sockaddr *) &l2a, sizeof(l2a)) < 0) { printf("Bind failed. %s (%d)\n", strerror(errno), errno); return -errno; } memset(&l2a, 0, sizeof(l2a)); l2a.l2_family = AF_BLUETOOTH; bacpy(&l2a.l2_bdaddr, dst); l2a.l2_psm = htobs(AVDTP_PSM); if (connect(sk, (struct sockaddr *) &l2a, sizeof(l2a)) < 0) { printf("Connect failed. %s(%d)\n", strerror(errno), errno); return -errno; } return sk;}static void usage(){ printf("avinfo - Audio/Video Info Tool ver %s\n", VERSION); printf("Usage:\n" "\tavinfo [options] <remote address>\n"); printf("Options:\n" "\t-h\t\tDisplay help\n" "\t-i\t\tSpecify source interface\n");}static struct option main_options[] = { { "help", 0, 0, 'h' }, { "device", 1, 0, 'i' }, { 0, 0, 0, 0 }};int main(int argc, char *argv[]){ bdaddr_t src, dst; int opt, sk, dev_id; if (argc < 2) { usage(); exit(0); } bacpy(&src, BDADDR_ANY); dev_id = hci_get_route(&src); if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0)) { printf("Cannot find any local adapter\n"); exit(-1); } while ((opt = getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) { switch (opt) { case 'i': if (!strncmp(optarg, "hci", 3)) hci_devba(atoi(optarg + 3), &src); else str2ba(optarg, &src); break; case 'h': default: usage(); exit(0); } } printf("Connecting ... \n"); if (bachk(argv[optind]) < 0) { printf("Invalid argument\n"); exit(1); } str2ba(argv[optind], &dst); sk = l2cap_connect(&src, &dst); if (sk < 0) exit(1); if (avdtp_discover(sk) < 0) exit(1); return 0;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -