From cf53da33a2c13d64eab583e23d028349af59d9e9 Mon Sep 17 00:00:00 2001 From: Stephane Bourque Date: Sat, 19 Dec 2020 14:46:25 -0800 Subject: [PATCH] Fixing API --- include/ovsdb_ap_tables.hrl | 20 -- priv/www/demo.html | 447 ++++++++++++++++++++++++++++++++++++ src/oui_server.erl | 26 ++- src/ovsdb_ap_config.erl | 8 +- 4 files changed, 471 insertions(+), 30 deletions(-) create mode 100644 priv/www/demo.html diff --git a/include/ovsdb_ap_tables.hrl b/include/ovsdb_ap_tables.hrl index 126f0a2..b336b20 100644 --- a/include/ovsdb_ap_tables.hrl +++ b/include/ovsdb_ap_tables.hrl @@ -13,26 +13,6 @@ -%%------------------------------------------------------------------------------ -%% auxiliary types - --record (version_matrix_map, { - 'DATE' = <<"Mon Nov 2 09">> :: term(), - 'FIRMWARE' = <<"0.1.0-0-notgit-development">> :: term(), - 'FW_BUILD' = <<"0">> :: term(), - 'FW_COMMIT' = <<"notgit">> :: term(), - 'FW_IMAGE_ACTIVE' = <<"ea8300-2020-11-02-pending-97ebe9d">> :: term(), - 'FW_IMAGE_INACTIVE' = <<"unknown">> :: term(), - 'FW_PROFILE' = <<"development">> :: term(), - 'FW_VERSION' = <<"0.1.0">> :: term(), - 'HOST' = <<"runner@72477083da86">> :: term(), - 'OPENSYNC' = <<"2.0.5.0">> :: term(), - 'core' = <<"2.0.5.0/0/notgit">> :: term(), - 'vendor/tip' = <<"0.1.0/0/notgit">> :: term() -}). - - - %%------------------------------------------------------------------------------ %% the tables diff --git a/priv/www/demo.html b/priv/www/demo.html new file mode 100644 index 0000000..16ee4ef --- /dev/null +++ b/priv/www/demo.html @@ -0,0 +1,447 @@ + + + + + + + OWLS + + + + + + +
+
+ +
+

^(OvO)^ OWLS

+ +
+ + + + + + +
+
+ +
+ +

API

+ +
+ + +
+ + +
+ + +
+ +
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + +
+ +
+ +
+ +

Nodes

+
    +
  • {{ node }}
  • +
+ +
+ +
+ +
+ +
+ +

Output

+
+ {{ msg }} +
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/src/oui_server.erl b/src/oui_server.erl index bd1e765..cc5ef66 100644 --- a/src/oui_server.erl +++ b/src/oui_server.erl @@ -21,7 +21,8 @@ -define(MAKER_LOOKUP_TABLE_FILENAME,"maker_lookup_table.ets"). %% API --export([start_link/0,creation_info/0,refresh/0,refresh/2,get_all/0,lookup_oui/1,lookup_vendor/1,get_an_oui/0,get_ouis/0,get_vendors/0]). +-export([start_link/0,creation_info/0,refresh/0,refresh/2,get_all/0,lookup_oui/1,lookup_vendor/1, + get_an_oui/0,get_ouis/0,get_vendors/0,lookup_oui_from_mac/1]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, @@ -64,16 +65,23 @@ get_vendors()-> gen_server:call(?SERVER,get_vendors). -spec lookup_oui(OUI:: string() | binary()) -> {ok,Vendor::binary()} | generic_error(). -lookup_oui(OUI) when is_list(OUI) -> - gen_server:call(?SERVER,{lookup_oui,list_to_binary(OUI)}); -lookup_oui(OUI) when is_binary(OUI) -> - gen_server:call(?SERVER,{lookup_oui,OUI}). +lookup_oui(OUI)-> + gen_server:call(?SERVER,{lookup_oui,utils:safe_binary(OUI)}). + +-spec lookup_oui_from_mac(OUI:: string() | binary()) -> {ok,Vendor::binary()} | generic_error(). +lookup_oui_from_mac(OUI)-> + try + <> = utils:safe_binary(OUI), + ProperOUI = list_to_binary(string:to_upper([X1,X2,X3,X4,X5,X6])), + gen_server:call(?SERVER,{lookup_oui,ProperOUI}) + catch + _:_ -> + { error, invalid_mac_address_format } + end. -spec lookup_vendor(Vendor::string() | binary() ) -> {ok,[ OUI::binary() ] } | generic_error(). -lookup_vendor(Vendor) when is_list(Vendor)-> - gen_server:call(?SERVER,{lookup_vendor,list_to_binary(Vendor)}); -lookup_vendor(Vendor) when is_binary(Vendor)-> - gen_server:call(?SERVER,{lookup_vendor,Vendor}). +lookup_vendor(Vendor)-> + gen_server:call(?SERVER,{lookup_vendor,utils:safe_binary(Vendor)}). %% @doc Spawns the server and registers the local name (unique) -spec(start_link() -> diff --git a/src/ovsdb_ap_config.erl b/src/ovsdb_ap_config.erl index 10a48a8..436db99 100644 --- a/src/ovsdb_ap_config.erl +++ b/src/ovsdb_ap_config.erl @@ -495,12 +495,18 @@ create_table ('Wifi_Associated_Clients',APC,Store) -> create_table ('DHCP_leased_IP',APC,Store) -> NM = proplists:get_value(name,APC), lists:foldl( fun(MAC,N)-> - ets:insert(Store, #'DHCP_leased_IP'{ + Vendor = case oui_server:lookup_oui_from_mac(MAC) of + {ok,X} -> X; + _ -> <<"unknown">> + end, + + ets:insert(Store, #'DHCP_leased_IP'{ '**key_id**' = utils:uuid_b(), '_version' = [<<"uuid">>, utils:uuid_b()], hostname = iolist_to_binary([proplists:get_value(name,APC),"_",integer_to_list(N)]), inet_addr = iolist_to_binary(["192.168.1.",integer_to_list(N+1)]), hwaddr = MAC, + vendor_class = Vendor, device_name = iolist_to_binary([NM,".SimClient_",integer_to_list(N+1)]) }), N+1