summaryrefslogtreecommitdiff
path: root/components/dlink_bt
diff options
context:
space:
mode:
authorUlf Wiger <ulf@feuerlabs.com>2015-12-13 11:59:25 -0800
committerUlf Wiger <ulf@feuerlabs.com>2015-12-13 11:59:25 -0800
commit88a73d73db0e06818b27ec4e6caeb2099be4e2e0 (patch)
tree206434dc830eb15bbf3d1687e149293237b8a768 /components/dlink_bt
parent2572d8c0c0ea55b55f4225005bcf706084bd456d (diff)
downloadrvi_core-88a73d73db0e06818b27ec4e6caeb2099be4e2e0.tar.gz
More robust listeners, lots of bugfixes for (and in) test suite
Diffstat (limited to 'components/dlink_bt')
-rw-r--r--components/dlink_bt/src/bt_connection.erl12
-rw-r--r--components/dlink_bt/src/bt_listener.erl2
-rw-r--r--components/dlink_bt/src/dlink_bt_rpc.erl14
3 files changed, 22 insertions, 6 deletions
diff --git a/components/dlink_bt/src/bt_connection.erl b/components/dlink_bt/src/bt_connection.erl
index 6b3a64e..bcfa199 100644
--- a/components/dlink_bt/src/bt_connection.erl
+++ b/components/dlink_bt/src/bt_connection.erl
@@ -138,7 +138,7 @@ init({connect, BTAddr, Channel, Mode, Mod, Fun, CS}) ->
{ok, PktMod} = get_module_config(packet_mod, ?PACKET_MOD, CS),
PktSt = PktMod:init(CS),
{ok, #st{
- remote_addr = BTAddr,
+ remote_addr = bt_addr(Mode, BTAddr),
channel = Channel,
rfcomm_ref = undefined,
mode = Mode,
@@ -394,9 +394,10 @@ handle_info({inet_async, _L, _Ref, {ok, Sock}} = Msg, #st{mod = Mod,
inet_db:register_socket(Sock, inet_tcp),
inet:setopts(Sock, [{active, once}]),
{ok, {BTAddr, Channel}} = inet:peername(Sock),
+ ?debug("peername (tcp): ~p:~p", [BTAddr, Channel]),
Mod:Fun(self(), BTAddr, Channel, accepted, Arg),
{noreply, St#st{rfcomm_ref = Sock,
- remote_addr = BTAddr}};
+ remote_addr = bt_addr(tcp, BTAddr)}};
handle_info(_Info, State) ->
?warning("~p:handle_info(): Unknown info: ~p", [ ?MODULE, _Info]),
@@ -442,3 +443,10 @@ handle_elements(Elements, #st{remote_addr = BTAddr,
?debug("data complete; processed: ~p",
[authorize_keys:abbrev(Elements)]),
Mod:Fun(self(), BTAddr, Channel, data, Elements, Arg).
+
+
+bt_addr(tcp, Addr) ->
+ {ok, IP} = inet:ip(Addr),
+ inet_parse:ntoa(IP);
+bt_addr(bt, Addr) ->
+ Addr.
diff --git a/components/dlink_bt/src/bt_listener.erl b/components/dlink_bt/src/bt_listener.erl
index a1f1a49..06efd3d 100644
--- a/components/dlink_bt/src/bt_listener.erl
+++ b/components/dlink_bt/src/bt_listener.erl
@@ -42,7 +42,7 @@ accept_ack(Result, LRef, Addr, Chan) ->
ok.
sock_opts() ->
- [binary, {active, once}, {packet, 0}].
+ [{reuseaddr, true}, binary, {active, once}, {packet, 0}].
init(Mode) ->
diff --git a/components/dlink_bt/src/dlink_bt_rpc.erl b/components/dlink_bt/src/dlink_bt_rpc.erl
index 69310a7..c675387 100644
--- a/components/dlink_bt/src/dlink_bt_rpc.erl
+++ b/components/dlink_bt/src/dlink_bt_rpc.erl
@@ -651,11 +651,19 @@ code_change(_OldVsn, St, _Extra) ->
send_authorize(Pid, SetupChannel, CompSpec) ->
- {ok,[{address, Address }]} = bt_drv:local_info([address]),
+ {Address, Channel} =
+ case Mode = get_mode(CompSpec) of
+ bt ->
+ {ok,[{address, Addr}]} = bt_drv:local_info([address]),
+ {bt_address_to_string(Addr), SetupChannel};
+ tcp ->
+ {IP, Port} = rvi_common:node_address_tuple(),
+ {IP, integer_to_binary(Port)}
+ end,
bt_connection:send(Pid,
[{ ?DLINK_ARG_CMD, ?DLINK_CMD_AUTHORIZE },
- { ?DLINK_ARG_ADDRESS, bt_address_to_string(Address) },
- { ?DLINK_ARG_PORT, SetupChannel },
+ { ?DLINK_ARG_ADDRESS, Address },
+ { ?DLINK_ARG_PORT, Channel },
{ ?DLINK_ARG_VERSION, ?DLINK_BT_VER },
{ ?DLINK_ARG_CREDENTIALS, get_credentials(CompSpec) }
| log_id_tail(CompSpec)]).