Skip to content

Commit

Permalink
Merge pull request #127 from rdkcentral/nbr_scans
Browse files Browse the repository at this point in the history
Neighbor Scans
  • Loading branch information
rshah-1 authored Jan 14, 2025
2 parents c45cb18 + 2ae4ad9 commit abf4e90
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 96 deletions.
1 change: 1 addition & 0 deletions inc/dm_easy_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "dm_dpp.h"
#include "dm_op_class.h"
#include "dm_policy.h"
#include "dm_scan_result.h"
#include "dm_radio_cap.h"
#include "dm_cac_comp.h"
#include "dm_ap_mld.h"
Expand Down
11 changes: 9 additions & 2 deletions inc/dm_easy_mesh_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "dm_bss_list.h"
#include "dm_sta_list.h"
#include "dm_policy_list.h"
#include "dm_scan_result_list.h"
#include "dm_dpp.h"
#include "db_client.h"
#include "dm_easy_mesh_list.h"
Expand All @@ -39,11 +40,11 @@ class dm_easy_mesh_t;
class em_mgr_t;

class dm_easy_mesh_ctrl_t :

public dm_network_list_t, public dm_device_list_t, public dm_network_ssid_list_t,
public dm_ieee_1905_security_list_t, public dm_radio_list_t, public dm_radio_cap_list_t,

public dm_op_class_list_t, public dm_bss_list_t, public dm_sta_list_t, public dm_policy_list_t {
public dm_op_class_list_t, public dm_bss_list_t, public dm_sta_list_t, public dm_policy_list_t,
public dm_scan_result_list_t {

db_client_t m_db_client;
bool m_initialized;
Expand Down Expand Up @@ -157,6 +158,12 @@ class dm_easy_mesh_ctrl_t :
void remove_policy(const char *key) { m_data_model_list.remove_policy(key); }
void put_policy(const char *key, const dm_policy_t *policy) { m_data_model_list.put_policy(key, policy); }

dm_scan_result_t *get_first_scan_result() { return m_data_model_list.get_first_scan_result(); }
dm_scan_result_t *get_next_scan_result(dm_scan_result_t *scan_result) { return m_data_model_list.get_next_scan_result(scan_result); }
dm_scan_result_t *get_scan_result(const char *key) { return m_data_model_list.get_scan_result(key); }
void remove_scan_result(const char *key) { m_data_model_list.remove_scan_result(key); }
void put_scan_result(const char *key, const dm_scan_result_t *scan_result) { m_data_model_list.put_scan_result(key, scan_result); }

void handle_dirty_dm();
void init_tables();
int load_tables();
Expand Down
6 changes: 6 additions & 0 deletions inc/dm_easy_mesh_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class dm_easy_mesh_list_t {
void remove_policy(const char *key);
void put_policy(const char *key, const dm_policy_t *policy);

dm_scan_result_t *get_first_scan_result();
dm_scan_result_t *get_next_scan_result(dm_scan_result_t *scan_result);
dm_scan_result_t *get_scan_result(const char *key);
void remove_scan_result(const char *key);
void put_scan_result(const char *key, const dm_scan_result_t *scan_result);

dm_easy_mesh_list_t();
~dm_easy_mesh_list_t();
};
Expand Down
9 changes: 7 additions & 2 deletions inc/dm_scan_result_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
#include "dm_scan_result.h"
#include "db_easy_mesh.h"

typedef struct {
em_scan_result_t *result;
unsigned int index;
} db_update_scan_result_t;

class dm_easy_mesh_t;
class dm_scan_result_list_t : public dm_scan_result_t, public db_easy_mesh_t {

public:
int init();

dm_orch_type_t get_dm_orch_type(db_client_t& db_client, const dm_scan_result_t& scan_result);
void update_list(const dm_scan_result_t& scan_result, dm_orch_type_t op);
dm_orch_type_t get_dm_orch_type(db_client_t& db_client, const dm_scan_result_t& scan_result, unsigned int index);
void update_list(const dm_scan_result_t& scan_result, unsigned int index, dm_orch_type_t op);
void delete_list();

void init_table();
Expand Down
9 changes: 6 additions & 3 deletions inc/em_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ extern "C"
#define EM_MAX_STA_PER_BSS 128
#define EM_MAX_STA_PER_STEER_POLICY 16
#define EM_MAX_STA_PER_AGENT (EM_MAX_RADIO_PER_AGENT * EM_MAX_STA_PER_BSS)
#define EM_MAX_NEIGHORS 32

#define EM_MAX_EVENT_DATA_LEN 4096*100
#define EM_MAX_CHANNELS_IN_LIST 9
Expand Down Expand Up @@ -650,7 +651,6 @@ typedef struct {
em_radio_id_t ruid;
unsigned char op_class;
unsigned char channel;
bssid_t bssid;
} em_scan_result_id_t;

typedef struct {
Expand All @@ -671,7 +671,8 @@ typedef struct {
em_long_string_t timestamp;
unsigned char util;
unsigned char noise;
em_neighbor_t neighbor;
unsigned int num_neighbors;
em_neighbor_t neighbor[EM_MAX_NEIGHORS];
} em_scan_result_t;

typedef struct {
Expand Down Expand Up @@ -2569,9 +2570,11 @@ typedef enum {
db_cfg_type_radio_cap_list_delete = (1 << 15),
db_cfg_type_1905_security_list_update = (1 << 16),
db_cfg_type_1905_security_list_delete = (1 << 17),
db_cfg_type_sta_metrics_update = (1 << 18),
db_cfg_type_sta_metrics_update = (1 << 18),
db_cfg_type_policy_list_update = (1 << 19),
db_cfg_type_policy_list_delete = (1 << 20),
db_cfg_type_scan_result_list_update = (1 << 21),
db_cfg_type_scan_result_list_delete = (1 << 22),
} db_cfg_type_t;

typedef struct{
Expand Down
41 changes: 23 additions & 18 deletions src/cli/em_cmd_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, c
em_network_node_t *child;
bool found_result = false;
unsigned int i;
em_long_string_t key;
char *net_id = m_cmd.m_param.u.args.args[1], *formatted, *node_str;

for (i = 0; i < node->num_children; i++) {
Expand All @@ -121,31 +122,35 @@ int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, c
}

if (found_result == false) {
new_node = em_net_node_t::clone_network_tree(node);;
} else {
child = em_net_node_t::clone_network_tree(node);;
}

snprintf(child->key, sizeof(em_long_string_t), "wfa-dataelements:%s", header);


snprintf(key, sizeof(em_long_string_t), "wfa-dataelements:%s", header);

if (child->num_children && strncmp(child->child[0]->key, key, strlen(key)) != 0) {
strncpy(child->key, key, strlen(key) + 1);
tmp = (em_network_node_t *)malloc(sizeof(em_network_node_t));
memset(tmp, 0, sizeof(em_network_node_t));
strncpy(tmp->key, "ID", strlen("ID") + 1);
tmp->type = em_network_node_data_type_string;
strncpy(tmp->value_str, net_id, strlen(net_id) + 1);
memset(tmp, 0, sizeof(em_network_node_t));
strncpy(tmp->key, "ID", strlen("ID") + 1);
tmp->type = em_network_node_data_type_string;
strncpy(tmp->value_str, net_id, strlen(net_id) + 1);

child->child[child->num_children] = tmp;
child->num_children++;
child->child[child->num_children] = tmp;
child->num_children++;

new_node = (em_network_node_t *)malloc(sizeof(em_network_node_t));
memset(new_node, 0, sizeof(em_network_node_t));
new_node->type = node->type;
new_node->child[new_node->num_children] = child;
new_node->num_children++;
memset(new_node, 0, sizeof(em_network_node_t));
new_node->type = node->type;
new_node->child[new_node->num_children] = child;
new_node->num_children++;
} else {
new_node = child;
}


//node_str = em_net_node_t::get_network_tree_string(new_node);
//m_cli.dump_lib_dbg(node_str);
//em_net_node_t::free_network_tree_string(node_str);
node_str = em_net_node_t::get_network_tree_string(new_node);
m_cli.dump_lib_dbg(node_str);
em_net_node_t::free_network_tree_string(node_str);
obj = (cJSON *)em_net_node_t::network_tree_to_json(new_node);
formatted = cJSON_Print(obj);
strncpy(buff, formatted, strlen(formatted) + 1);
Expand Down
75 changes: 40 additions & 35 deletions src/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,6 @@ type EasyMeshCmd struct {
Help string
}

var easyMeshCommands = map[string]EasyMeshCmd {
NetworkTopologyCmd: {NetworkTopologyCmd, 0, "get_bss OneWifiMesh", "", "", ""},
NetworkPolicyCmd: {NetworkPolicyCmd, 1, "get_policy OneWifiMesh", "get_policy OneWifiMesh", "set_policy OneWifiMesh", ""},
NetworkSSIDListCmd: {NetworkSSIDListCmd, 2, "get_ssid OneWifiMesh", "get_ssid OneWifiMesh", "set_ssid OneWifiMesh", ""},
RadioListCmd: {RadioListCmd, 3, "get_radio OneWifiMesh", "", "", ""},
ChannelsListCmd: {ChannelsListCmd, 4, "get_channel OneWifiMesh", "get_channel OneWifiMesh 1", "set_channel OneWifiMesh", ""},
NeighborsListCmd: {NeighborsListCmd, 5, "get_channel OneWifiMesh", "get_channel OneWifiMesh 2", "scan_channel OneWifiMesh", ""},
ClientDevicesCmd: {ClientDevicesCmd, 6, "get_sta OneWifiMesh", "", "", ""},
SteerDevicesCmd: {SteerDevicesCmd, 7, "get_sta OneWifiMesh", "get_sta OneWifiMesh 1", "steer_sta OneWifiMesh", ""},
NetworkMetricsCmd: {NetworkMetricsCmd, 8, "", "", "", ""},
DeviceOnboardingCmd: {DeviceOnboardingCmd, 9, "", "", "start_dpp OneWifiMesh", ""},
WiFiEventsCmd: {WiFiEventsCmd, 10, "", "", "", ""},
WiFiResetCmd: {WiFiResetCmd, 11, "get_network OneWifiMesh", "", "reset OneWifiMesh", ""},
DebugCmd: {DebugCmd, 12, "dev_test OneWifiMesh", "", "", ""},
}

type model struct {
platform string
list list.Model
Expand All @@ -158,17 +142,35 @@ type model struct {
quit chan bool
ticker *time.Ticker
timer *time.Timer
easyMeshCommands map[string]EasyMeshCmd
contentUpdated bool
dump *os.File
}

func newModel(platform string) model {

easyMeshCommands := map[string]EasyMeshCmd {
NetworkTopologyCmd: {NetworkTopologyCmd, 0, "get_bss OneWifiMesh", "", "", ""},
NetworkPolicyCmd: {NetworkPolicyCmd, 1, "get_policy OneWifiMesh", "get_policy OneWifiMesh", "set_policy OneWifiMesh", ""},
NetworkSSIDListCmd: {NetworkSSIDListCmd, 2, "get_ssid OneWifiMesh", "get_ssid OneWifiMesh", "set_ssid OneWifiMesh", ""},
RadioListCmd: {RadioListCmd, 3, "get_radio OneWifiMesh", "", "", ""},
ChannelsListCmd: {ChannelsListCmd, 4, "get_channel OneWifiMesh", "get_channel OneWifiMesh 1", "set_channel OneWifiMesh", ""},
NeighborsListCmd: {NeighborsListCmd, 5, "get_channel OneWifiMesh", "get_channel OneWifiMesh 2", "scan_channel OneWifiMesh", ""},
ClientDevicesCmd: {ClientDevicesCmd, 6, "get_sta OneWifiMesh", "", "", ""},
SteerDevicesCmd: {SteerDevicesCmd, 7, "get_sta OneWifiMesh", "get_sta OneWifiMesh 1", "steer_sta OneWifiMesh", ""},
NetworkMetricsCmd: {NetworkMetricsCmd, 8, "", "", "", ""},
DeviceOnboardingCmd: {DeviceOnboardingCmd, 9, "", "", "", ""},
WiFiEventsCmd: {WiFiEventsCmd, 10, "", "", "", ""},
WiFiResetCmd: {WiFiResetCmd, 11, "get_network OneWifiMesh", "", "reset OneWifiMesh", ""},
DebugCmd: {DebugCmd, 12, "dev_test OneWifiMesh", "", "", ""},
}

var items []list.Item

for i := 0; i < len(easyMeshCommands); i++ {
for _, value := range easyMeshCommands {
if i == value.LoadOrder {
items = append(items, item{title: value.Title})
items = append(items, item{title: value.Title})
break
}
}
Expand Down Expand Up @@ -211,24 +213,23 @@ func newModel(platform string) model {
activeButton: BTN_CANCEL,
tree: etree.New(nodes, false, w, h, dump),
dump: dump,
easyMeshCommands: easyMeshCommands,
contentUpdated: false,
}
}



func (m model) Init() tea.Cmd {
var params *C.em_cli_params_t

params = (*C.em_cli_params_t)(C.malloc(C.sizeof_em_cli_params_t))

params.user_data = unsafe.Pointer(&m)
params.cb_func = nil
params.cli_type = C.em_cli_type_go
C.init(params)

m.currentOperatingInstructions = "\n\n\t Press 'w' to scroll up, 's' to scroll down"

C.init(params)

m.timer = time.NewTimer(1 * time.Second)
m.ticker = time.NewTicker(5 * time.Second)
m.quit = make(chan bool)
Expand All @@ -250,7 +251,6 @@ func (m *model) timerHandler() {


case <- m.ticker.C:
//spew.Fdump(m.dump, "5 second ticker fired")

case <- m.quit:
m.ticker.Stop()
Expand Down Expand Up @@ -344,7 +344,7 @@ func (m model) nodesToTree(netNode *C.em_network_node_t, treeNode *etree.Node) {
}

func (m *model) execSelectedCommand(cmdStr string, cmdType int) {
for _, value := range easyMeshCommands {
for _, value := range m.easyMeshCommands {
if cmdStr == value.Title {
switch cmdType {
case GET:
Expand All @@ -363,7 +363,6 @@ func (m *model) execSelectedCommand(cmdStr string, cmdType int) {
}
m.currentNetNode = C.exec(C.CString(value.GetCommand), C.strlen(C.CString(value.GetCommand)), nil)
if m.currentNetNode == nil {
spew.Fprintf(m.dump, "%s returned nil\n", value.GetCommand);
return
}
treeNode := make([]etree.Node, 1)
Expand Down Expand Up @@ -425,18 +424,22 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch msg := msg.(type) {
case tea.WindowSizeMsg:
w, h:= appStyle.GetFrameSize()
spew.Fprintf(m.dump, "Frame Width: %d Frame Height: %d Msg Width: %d Msg Height: %d\n",
w, h, msg.Width, msg.Height)

m.menuHeight = msg.Height - m.bottomSpace - m.menuInstructionsHeight
m.canvasWidth = msg.Width - m.menuWidth - m.rightSpace
m.canvasHeight = msg.Height - m.bottomSpace

case tea.KeyMsg:
switch msg.String() {
case "tab":
m.activeButton = (m.activeButton + 1) % BTN_MAX
if m.contentUpdated == true {
m.activeButton = (m.activeButton + 1) % BTN_MAX
} else {
if m.activeButton == BTN_UPDATE {
m.activeButton = BTN_CANCEL
} else {
m.activeButton = BTN_UPDATE
}
}

case "j", "k":
m.currentOperatingInstructions = "\n\n\t Press 'w' to scroll up, 's' to scroll down"
Expand All @@ -455,24 +458,26 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if selectedItem, ok := m.list.SelectedItem().(item); ok {
m.execSelectedCommand(selectedItem.title, GET)
}

m.contentUpdated = false

}

case "down":
if m.scrollIndex < m.tree.Cursor() {
m.scrollIndex++
}
spew.Fprintf(m.dump, "down: %d\n", m.scrollIndex);

case "up":
if m.scrollIndex > 0 {
m.scrollIndex--
}
spew.Fprintf(m.dump, "up: %d\n", m.scrollIndex);

case "enter":
if m.activeButton == BTN_UPDATE {
m.currentOperatingInstructions = "\n\n\t Editor Mode: Press 'Apply' to apply settings, 'Cancel' to leave"
if selectedItem, ok := m.list.SelectedItem().(item); ok {
m.contentUpdated = true
m.execSelectedCommand(selectedItem.title, GETX)
}
m.tree.SetEditable(true)
Expand Down Expand Up @@ -583,21 +588,21 @@ func (m model) View() string {
statusView = styledContent + m.currentOperatingInstructions

updateButton := buttonStyle.Render("Update")
okButton := buttonStyle.Render("Apply")
applyButton := buttonStyle.Render("Apply")
cancelButton := buttonStyle.Render("Cancel")

switch m.activeButton {
case BTN_UPDATE:
updateButton = activeButtonStyle.Render("Update")

case BTN_APPLY:
okButton = activeButtonStyle.Render("Apply")
applyButton = activeButtonStyle.Render("Apply")

case BTN_CANCEL:
cancelButton = activeButtonStyle.Render("Cancel")
}

buttons := lipgloss.JoinHorizontal(lipgloss.Center, updateButton, okButton, cancelButton)
buttons := lipgloss.JoinHorizontal(lipgloss.Center, updateButton, applyButton, cancelButton)
centeredButtons := lipgloss.NewStyle().Width(100).Align(lipgloss.Center).Render(buttons)
statusView = statusView + "\n\n" + centeredButtons

Expand Down
4 changes: 4 additions & 0 deletions src/ctrl/dm_easy_mesh_ctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ int dm_easy_mesh_ctrl_t::reset_config()
dm_bss_list_t::load_table(m_db_client);
dm_sta_list_t::load_table(m_db_client);
dm_policy_list_t::load_table(m_db_client);
dm_scan_result_list_t::load_table(m_db_client);

return 0;
}
Expand Down Expand Up @@ -1392,6 +1393,7 @@ void dm_easy_mesh_ctrl_t::init_tables()
dm_bss_list_t::init();
dm_sta_list_t::init();
dm_policy_list_t::init();
dm_scan_result_list_t::init();
}

int dm_easy_mesh_ctrl_t::load_net_ssid_table()
Expand Down Expand Up @@ -1419,6 +1421,8 @@ int dm_easy_mesh_ctrl_t::load_tables()
type = db_cfg_type_sta_list_update;
} else if (dm_policy_list_t::load_table(m_db_client) != 0) {
type = db_cfg_type_policy_list_update;
} else if (dm_scan_result_list_t::load_table(m_db_client) != 0) {
type = db_cfg_type_scan_result_list_update;
}

if (type == dm_orch_type_none) {
Expand Down
Loading

0 comments on commit abf4e90

Please sign in to comment.