Home | History | Annotate | Download | only in btio

Lines Matching refs:sock

152 		int err = 0, sock = g_io_channel_unix_get_fd(io);
155 if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len) < 0)
256 static int l2cap_bind(int sock, const bdaddr_t *src, uint16_t psm,
270 if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
278 static int l2cap_connect(int sock, const bdaddr_t *dst,
292 err = connect(sock, (struct sockaddr *) &addr, sizeof(addr));
299 static int l2cap_set_master(int sock, int master)
305 if (getsockopt(sock, SOL_L2CAP, L2CAP_LM, &flags, &len) < 0)
318 if (setsockopt(sock, SOL_L2CAP, L2CAP_LM, &flags, sizeof(flags)) < 0)
324 static int rfcomm_set_master(int sock, int master)
330 if (getsockopt(sock, SOL_RFCOMM, RFCOMM_LM, &flags, &len) < 0)
343 if (setsockopt(sock, SOL_RFCOMM, RFCOMM_LM, &flags, sizeof(flags)) < 0)
349 static int l2cap_set_lm(int sock, int level)
358 if (setsockopt(sock, SOL_L2CAP, L2CAP_LM, &opt, sizeof(opt)) < 0)
364 static int rfcomm_set_lm(int sock, int level)
373 if (setsockopt(sock, SOL_RFCOMM, RFCOMM_LM, &opt, sizeof(opt)) < 0)
379 static gboolean set_force_active(int sock, BtIOType type, uint8_t force_active,
387 if (setsockopt(sock, SOL_BLUETOOTH, BT_POWER, &pwr,
399 static gboolean set_sec_level(int sock, BtIOType type, int level, GError **err)
414 if (setsockopt(sock, SOL_BLUETOOTH, BT_SECURITY, &sec,
424 ret = l2cap_set_lm(sock, level);
426 ret = rfcomm_set_lm(sock, level);
436 static int l2cap_get_lm(int sock, int *sec_level)
442 if (getsockopt(sock, SOL_L2CAP, L2CAP_LM, &opt, &len) < 0)
457 static int rfcomm_get_lm(int sock, int *sec_level)
463 if (getsockopt(sock, SOL_RFCOMM, RFCOMM_LM, &opt, &len) < 0)
478 static gboolean get_force_active(int sock, BtIOType type, uint8_t *force_active,
486 if (getsockopt(sock, SOL_BLUETOOTH, BT_POWER, &pwr, &len) == 0) {
499 static gboolean get_sec_level(int sock, BtIOType type, int *level,
508 if (getsockopt(sock, SOL_BLUETOOTH, BT_SECURITY, &sec, &len) == 0) {
519 ret = l2cap_get_lm(sock, level);
521 ret = rfcomm_get_lm(sock, level);
531 static int l2cap_set_flushable(int sock, gboolean flushable)
536 if (setsockopt(sock, SOL_BLUETOOTH, BT_FLUSHABLE, &f, sizeof(f)) < 0)
542 static gboolean l2cap_set(int sock, int sec_level, uint16_t imtu,
552 if (getsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o,
565 if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o,
572 if (master >= 0 && l2cap_set_master(sock, master) < 0) {
577 if (flushable >= 0 && l2cap_set_flushable(sock, flushable) < 0) {
582 if (sec_level && !set_sec_level(sock, BT_IO_L2CAP, sec_level, err))
585 if (!set_force_active(sock, BT_IO_L2CAP, force_active, err))
591 static int rfcomm_bind(int sock,
601 if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
609 static int rfcomm_connect(int sock, const bdaddr_t *dst, uint8_t channel)
619 err = connect(sock, (struct sockaddr *) &addr, sizeof(addr));
626 static gboolean rfcomm_set(int sock, int sec_level, int master,
629 if (sec_level && !set_sec_level(sock, BT_IO_RFCOMM, sec_level, err))
632 if (!set_force_active(sock, BT_IO_RFCOMM, force_active, err))
635 if (master >= 0 && rfcomm_set_master(sock, master) < 0) {
643 static int sco_bind(int sock, const bdaddr_t *src, GError **err)
651 if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
659 static int sco_connect(int sock, const bdaddr_t *dst)
668 err = connect(sock, (struct sockaddr *) &addr, sizeof(addr));
675 static gboolean sco_set(int sock, uint16_t mtu, GError **err)
685 if (getsockopt(sock, SOL_SCO, SCO_OPTIONS, &sco_opt, &len) < 0) {
691 if (setsockopt(sock, SOL_SCO, SCO_OPTIONS, &sco_opt,
788 static gboolean get_peers(int sock, struct sockaddr *src, struct sockaddr *dst,
795 if (getsockname(sock, src, &olen) < 0) {
802 if (getpeername(sock, dst, &olen) < 0) {
810 static int l2cap_get_info(int sock, uint16_t *handle, uint8_t *dev_class)
816 if (getsockopt(sock, SOL_L2CAP, L2CAP_CONNINFO, &info, &len) < 0)
828 static int l2cap_get_flushable(int sock, gboolean *flushable)
835 if (getsockopt(sock, SOL_BLUETOOTH, BT_FLUSHABLE, &f, &len) < 0)
846 static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
860 if (getsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, &len) < 0) {
865 if (!get_peers(sock, (struct sockaddr *) &src,
885 if (getsockopt(sock, SOL_BLUETOOTH, BT_DEFER_SETUP,
893 if (!get_sec_level(sock, BT_IO_L2CAP,
913 if (getsockopt(sock, SOL_L2CAP, L2CAP_LM, &flags,
923 if (l2cap_get_info(sock, &handle, dev_class) < 0) {
930 if (l2cap_get_info(sock, &handle, dev_class) < 0) {
940 if (l2cap_get_flushable(sock, &flushable) < 0) {
947 if (!get_force_active(sock, BT_IO_L2CAP,
963 static int rfcomm_get_info(int sock, uint16_t *handle, uint8_t *dev_class)
969 if (getsockopt(sock, SOL_RFCOMM, RFCOMM_CONNINFO, &info, &len) < 0)
981 static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1,
991 if (!get_peers(sock, (struct sockaddr *) &src,
1011 if (getsockopt(sock, SOL_BLUETOOTH, BT_DEFER_SETUP,
1019 if (!get_sec_level(sock, BT_IO_RFCOMM,
1035 if (getsockopt(sock, SOL_RFCOMM, RFCOMM_LM, &flags,
1045 if (rfcomm_get_info(sock, &handle, dev_class) < 0) {
1052 if (rfcomm_get_info(sock, &handle, dev_class) < 0) {
1059 if (!get_force_active(sock, BT_IO_RFCOMM,
1075 static int sco_get_info(int sock, uint16_t *handle, uint8_t *dev_class)
1081 if (getsockopt(sock, SOL_SCO, SCO_CONNINFO, &info, &len) < 0)
1093 static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args)
1104 if (getsockopt(sock, SOL_SCO, SCO_OPTIONS, &sco_opt, &len) < 0) {
1109 if (!get_peers(sock, (struct sockaddr *) &src,
1133 if (sco_get_info(sock, &handle, dev_class) < 0) {
1140 if (sco_get_info(sock, &handle, dev_class) < 0) {
1161 int sock;
1163 sock = g_io_channel_unix_get_fd(io);
1168 return l2cap_get(sock, err, opt1, args);
1170 return rfcomm_get(sock, err, opt1, args);
1172 return sco_get(sock, err, opt1, args);
1183 int sock;
1187 sock = g_io_channel_unix_get_fd(io);
1190 pfd.fd = sock;
1199 if (read(sock, &c, 1) < 0) {
1216 int sock;
1225 sock = g_io_channel_unix_get_fd(io);
1230 return l2cap_set(sock, opts.sec_level, opts.imtu, opts.omtu,
1234 return rfcomm_set(sock, opts.sec_level, opts.master, opts.force_active,
1237 return sco_set(sock, opts.mtu, err);
1261 int sock;
1266 sock = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP);
1267 if (sock < 0) {
1271 if (l2cap_bind(sock, &opts->src, server ? opts->psm : 0,
1274 if (!l2cap_set(sock, opts->sec_level, 0, 0, 0, -1, -1, opts->force_active,
1279 sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
1280 if (sock < 0) {
1284 if (l2cap_bind(sock, &opts->src, server ? opts->psm : 0,
1287 if (!l2cap_set(sock, opts->sec_level, opts->imtu, opts->omtu,
1293 sock = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1294 if (sock < 0) {
1298 if (rfcomm_bind(sock, &opts->src,
1301 if (!rfcomm_set(sock, opts->sec_level, opts->master,
1306 sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
1307 if (sock < 0) {
1311 if (sco_bind(sock, &opts->src, err) < 0)
1313 if (!sco_set(sock, opts->mtu, err))
1322 io = g_io_channel_unix_new(sock);
1330 close(sock);
1342 int err, sock;
1356 sock = g_io_channel_unix_get_fd(io);
1360 err = l2cap_connect(sock, &opts.dst, 0, opts.cid);
1363 err = l2cap_connect(sock, &opts.dst, opts.psm, opts.cid);
1366 err = rfcomm_connect(sock, &opts.dst, opts.channel);
1369 err = sco_connect(sock, &opts.dst);
1397 int sock;
1417 sock = g_io_channel_unix_get_fd(io);
1420 setsockopt(sock, SOL_BLUETOOTH, BT_DEFER_SETUP, &opts.defer,
1423 if (listen(sock, 5) < 0) {