123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- /**
- * \file appl_proxy.c
- *
- *
- */
- /*
- * Copyright (C) 2017. Mindtree Limited.
- * All rights reserved.
- */
- /* --------------------------------------------- Header File Inclusion */
- #include "appl_main.h"
- #include "blebrr.h"
- #include "MS_net_api.h"
- #ifdef MS_PROXY_SUPPORT
- /* --------------------------------------------- External Global Variables */
- /* --------------------------------------------- Exported Global Variables */
- /* --------------------------------------------- Static Global Variables */
- DECL_STATIC const char main_proxy_options[] = "\n\
- ========= Network Menu =============== \n\
- 0. Exit. \n\
- 1. Refresh \n\
- \n\
- 10. Register with Proxy Layer \n\
- \n\
- 20. Start Proxy ADV with Network ID \n\
- 21. Start Proxy ADV with Node Identity \n\
- 22. Stop Proxy ADV \n\
- \n\
- 30. Set WhiteList Filter Type \n\
- 31. Set BlackList Filter Type \n\
- 32. Add Address to Filter \n\
- 33. Remove Address from Filter \n\
- \n\
- 200. Enable Proxy \n\
- 201. Disable Proxy \n\
- Your Option ? \0";
- /* Global Network Interface Handle : Initialize to MAX Ifaces[Invalid Value] */
- NETIF_HANDLE g_appl_netif_hndl;
- /* --------------------------------------------- Functions */
- void appl_proxy_callback
- (
- NETIF_HANDLE * handle,
- UCHAR p_evt,
- UCHAR * data_param,
- UINT16 data_len
- );
- void appl_add_or_del_filter_addr(UCHAR opcode);
- void appl_proxy_start_net_id_adv(MS_SUBNET_HANDLE subnet_handle);
- void appl_proxy_start_node_identity_adv(MS_SUBNET_HANDLE subnet_handle);
- void main_proxy_operations (void);
- void main_proxy_operations (void)
- {
- int choice;
- static UINT8 first_time = 0;
- if (0 == first_time)
- {
- g_appl_netif_hndl = (NETIF_HANDLE)MS_CONFIG_LIMITS(MS_NUM_NETWORK_INTERFACES);
- first_time = 1;
- }
- MS_LOOP_FOREVER()
- {
- printf("%s", main_proxy_options);
- scanf("%d", &choice);
- if (choice < 0)
- {
- printf("*** Invalid Choice. Try Again.\n");
- continue;
- }
- switch (choice)
- {
- case 0:
- return;
- case 1:
- break;
- case 10:
- /* Register with the Proxy Layer */
- MS_proxy_register(appl_proxy_callback);
- break;
- case 20:
- #ifdef MS_PROXY_SERVER
- /* Start Proxy ADV with Network ID */
- printf("\nEnter Subnet Handle :\n");
- scanf("%d", &choice);
- appl_proxy_start_net_id_adv((MS_SUBNET_HANDLE)choice);
- #else /* MS_PROXY_SERVER */
- CONSOLE_OUT(
- "Proxy Server Feature Currently Disabled!!!\n");
- #endif /* MS_PROXY_SERVER */
- break;
- case 21:
- #ifdef MS_PROXY_SERVER
- /* Start Proxy ADV with Node Identity */
- printf("\nEnter Subnet Handle :\n");
- scanf("%d", &choice);
- appl_proxy_start_node_identity_adv((MS_SUBNET_HANDLE)choice);
- #else /* MS_PROXY_SERVER */
- CONSOLE_OUT(
- "Proxy Server Feature Currently Disabled!!!\n");
- #endif /* MS_PROXY_SERVER */
- break;
- case 22:
- #ifdef MS_PROXY_SERVER
- /* Stop Proxy ADV */
- MS_proxy_server_adv_stop();
- #else /* MS_PROXY_SERVER */
- CONSOLE_OUT(
- "Proxy Server Feature Currently Disabled!!!\n");
- #endif /* MS_PROXY_SERVER */
- break;
- case 30:
- #ifdef MS_PROXY_CLIENT
- /* Set Filter Type as WhiteList */
- MS_proxy_set_whitelist_filter(&g_appl_netif_hndl, 0x0000);
- #else /* MS_PROXY_CLIENT */
- CONSOLE_OUT(
- "Proxy Client Feature Currently Disabled!!!\n");
- #endif /* MS_PROXY_CLIENT */
- break;
- case 31:
- #ifdef MS_PROXY_CLIENT
- /* Set Filter Type as BlackList */
- MS_proxy_set_blacklist_filter(&g_appl_netif_hndl, 0x0000);
- #else /* MS_PROXY_CLIENT */
- CONSOLE_OUT(
- "Proxy Client Feature Currently Disabled!!!\n");
- #endif /* MS_PROXY_CLIENT */
- break;
- case 32:
- /* Add Address to Filters */
- appl_add_or_del_filter_addr(MS_PROXY_ADD_TO_FILTER_OPCODE);
- break;
- case 33:
- /* Remove Address from Filters */
- appl_add_or_del_filter_addr(MS_PROXY_REM_FROM_FILTER_OPCODE);
- break;
- case 200:
- /* Enable Proxy */
- MS_ENABLE_PROXY_FEATURE();
- break;
- case 201:
- /* Disable Proxy */
- MS_DISABLE_PROXY_FEATURE();
- break;
- default:
- printf ("Invalid option %d\n", choice);
- }
- }
- }
- void appl_proxy_callback
- (
- NETIF_HANDLE * handle,
- UCHAR p_evt,
- UCHAR * data_param,
- UINT16 data_len
- )
- {
- PROXY_FILTER_TYPE filter_type;
- UINT16 count;
- UCHAR role;
- MS_IGNORE_UNUSED_PARAM(data_len);
- switch(p_evt)
- {
- case MS_PROXY_UP_EVENT:
- CONSOLE_OUT(
- "\n\n[PROXY APPL]: MS_PROXY_UP_EVENT Received for NETIF Handle 0x%02X\n\n", *handle);
- g_appl_netif_hndl = *handle;
- CONSOLE_OUT(
- "\n[PROXY APPL]: Enabling Proxy Feature!!\n");
- if (NULL != data_param)
- {
- /* Catch the current role into a local */
- role = data_param[0];
- if (BRR_SERVER_ROLE == role)
- {
- /* Enable Proxy */
- MS_ENABLE_PROXY_FEATURE();
- /* Send Secure Network Beacons */
- MS_net_broadcast_secure_beacon(0x0000);
- }
- }
- break;
- case MS_PROXY_DOWN_EVENT:
- CONSOLE_OUT(
- "\n\n[PROXY APPL]: MS_PROXY_DOWN_EVENT Received for NETIF Handle 0x%02X\n\n", *handle);
- g_appl_netif_hndl = (NETIF_HANDLE)MS_CONFIG_LIMITS(MS_NUM_NETWORK_INTERFACES);
- CONSOLE_OUT(
- "\n[PROXY APPL]: Disabling Proxy Feature!!\n");
- /* Disable Proxy */
- MS_DISABLE_PROXY_FEATURE();
- break;
- case MS_PROXY_STATUS_EVENT:
- /* TODO: Length Check */
- /* Extract the Status contents */
- filter_type = data_param[0];
- MS_UNPACK_BE_2_BYTE(&count, &data_param[1]);
- CONSOLE_OUT(
- "\n\n[PROXY APPL]: MS_PROXY_STATUS_EVENT Received for NETIF Handle 0x%02X\n"
- "Filter Type :- %s\r\n Addr Count :- %04d\n\n",
- *handle,
- (MS_PROXY_WHITELIST_FILTER == filter_type)? "WhiteList":
- "BlackList",
- count);
- break;
- default:
- CONSOLE_OUT(
- "\n\n[PROXY APPL ERR]: Unknown Event Received for NETIF Handle 0x%02X!!\n\n", *handle);
- break;
- }
- }
- void appl_add_or_del_filter_addr(UCHAR opcode)
- {
- #ifdef MS_PROXY_CLIENT
- PROXY_ADDR appl_proxy_addr_list[5];
- UINT16 addr_count;
- UINT32 index;
- int read_in;
- /* Read and fill Addresses */
- CONSOLE_OUT("Enter Count of Address to be Added (in Hex)\n");
- CONSOLE_IN("%x", &read_in);
- addr_count = (UINT16)read_in;
- for (index = 0; index < addr_count; index++)
- {
- CONSOLE_OUT("Enter %d'th Address[in HEX]: \n", (index + 1));
- CONSOLE_IN("%x", &read_in);
- appl_proxy_addr_list[index] = (UINT8)read_in;
- }
- if (MS_PROXY_ADD_TO_FILTER_OPCODE == opcode)
- {
- MS_proxy_add_to_list
- (
- &g_appl_netif_hndl,
- 0x0000,
- appl_proxy_addr_list,
- addr_count
- );
- }
- else
- {
- MS_proxy_del_from_list
- (
- &g_appl_netif_hndl,
- 0x0000,
- appl_proxy_addr_list,
- addr_count
- );
- }
- #else /* MS_PROXY_CLIENT */
- MS_IGNORE_UNUSED_PARAM(opcode);
- CONSOLE_OUT(
- "Proxy Client Feature Currently Disabled!!!\n");
- #endif /* MS_PROXY_CLIENT */
- }
- void appl_proxy_register(void)
- {
- MS_proxy_register(appl_proxy_callback);
- }
- void appl_proxy_start_net_id_adv(MS_SUBNET_HANDLE subnet_handle)
- {
- #ifdef MS_PROXY_SERVER
- /* Set the role to Proxy with bearer */
- blebrr_gatt_mode_set(BLEBRR_GATT_PROXY_MODE);
- MS_proxy_server_adv_start
- (
- subnet_handle,
- MS_PROXY_NET_ID_ADV_MODE
- );
- #else /* MS_PROXY_SERVER */
- CONSOLE_OUT(
- "Proxy Server Feature Currently Disabled!!!\n");
- return API_FAILURE;
- #endif /* MS_PROXY_SERVER */
- }
- void appl_proxy_start_node_identity_adv(MS_SUBNET_HANDLE subnet_handle)
- {
- #ifdef MS_PROXY_SERVER
- /* Set the role to Proxy with bearer */
- blebrr_gatt_mode_set(BLEBRR_GATT_PROXY_MODE);
- MS_proxy_server_adv_start
- (
- subnet_handle,
- MS_PROXY_NODE_ID_ADV_MODE
- );
- #else /* MS_PROXY_SERVER */
- CONSOLE_OUT(
- "Proxy Server Feature Currently Disabled!!!\n");
- return API_FAILURE;
- #endif /* MS_PROXY_SERVER */
- }
- void appl_proxy_adv
- (
- UCHAR identification_type,
- MS_SUBNET_HANDLE subnet_handle
- )
- {
- #ifdef MS_PROXY_SERVER
- (MS_PROXY_NET_ID_ADV_MODE == identification_type) ?
- appl_proxy_start_net_id_adv(subnet_handle) : appl_proxy_start_node_identity_adv(subnet_handle);
- #else /* MS_PROXY_SERVER */
- CONSOLE_OUT(
- "Proxy Server Feature Currently Disabled!!!\n");
- return API_FAILURE;
- #endif /* MS_PROXY_SERVER */
- }
- #endif /* MS_PROXY_SUPPORT */
|