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