mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
add object
This commit is contained in:
parent
4c16b53e5d
commit
8eaba26974
5 changed files with 48 additions and 5 deletions
|
|
@ -23,6 +23,7 @@ uint8_t mac_list[MAC_LIST_LENGTH][ETH_ALEN];
|
|||
|
||||
// ---------------- Functions ----------
|
||||
void insert_macs_from_file();
|
||||
int insert_to_maclist(uint8_t mac[]);
|
||||
|
||||
|
||||
/* Metric */
|
||||
|
|
|
|||
|
|
@ -15,4 +15,6 @@ int hwaddr_aton(const char *txt, uint8_t *addr);
|
|||
|
||||
int convert_mac(char *in, char *out);
|
||||
|
||||
void write_mac_to_file(char* path, uint8_t addr[]);
|
||||
|
||||
#endif
|
||||
|
|
@ -638,9 +638,24 @@ void insert_macs_from_file()
|
|||
fclose(fp);
|
||||
if (line)
|
||||
free(line);
|
||||
exit(EXIT_SUCCESS);
|
||||
//exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int insert_to_maclist(uint8_t mac[])
|
||||
{
|
||||
if(mac_in_maclist(mac))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
mac_list_entry_last++;
|
||||
for (int i = 0; i < ETH_ALEN; ++i) {
|
||||
mac_list[mac_list_entry_last][i] = mac[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int mac_in_maclist(uint8_t mac[])
|
||||
{
|
||||
for(int i = 0; i <= mac_list_entry_last; i++)
|
||||
|
|
|
|||
|
|
@ -136,9 +136,15 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir);
|
|||
|
||||
static int ubus_get_clients();
|
||||
|
||||
static int
|
||||
add_mac(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg);
|
||||
|
||||
int hostapd_array_check_id(uint32_t id);
|
||||
void hostapd_array_insert(uint32_t id);
|
||||
void hostapd_array_delete(uint32_t id);
|
||||
static void ubus_add_oject();
|
||||
|
||||
int hostapd_array_check_id(uint32_t id)
|
||||
{
|
||||
|
|
@ -700,11 +706,11 @@ static const struct blobmsg_policy add_del_policy[__ADD_DEL_MAC_MAX] = {
|
|||
};
|
||||
|
||||
static const struct ubus_method dawn_methods[] = {
|
||||
UBUS_METHOD("hello", test_hello, add_del_policy),
|
||||
UBUS_METHOD("add_mac", add_mac, add_del_policy),
|
||||
};
|
||||
|
||||
static struct ubus_object_type dawn_object_type =
|
||||
UBUS_OBJECT_TYPE("test", dawn_methods);
|
||||
UBUS_OBJECT_TYPE("dawn", dawn_methods);
|
||||
|
||||
static struct ubus_object dawn_object = {
|
||||
.name = "dawn",
|
||||
|
|
@ -729,10 +735,13 @@ add_mac(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
if (hwaddr_aton(blobmsg_data(tb[MAC_ADDR]), addr))
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
|
||||
printf("ADDED SOME MAC!\n");
|
||||
insert_to_maclist(addr);
|
||||
write_mac_to_file("/etc/dawn/mac_list", addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ubus_add_oject(void)
|
||||
static void ubus_add_oject()
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
|
|
|||
|
|
@ -44,3 +44,19 @@ int convert_mac(char *in, char *out) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void write_mac_to_file(char* path, uint8_t addr[])
|
||||
{
|
||||
FILE *f = fopen(path, "a");
|
||||
if (f == NULL)
|
||||
{
|
||||
printf("Error opening file!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char mac_buf[20];
|
||||
sprintf(mac_buf, MACSTR, MAC2STR(addr));
|
||||
|
||||
fprintf(f, "%s\n", mac_buf);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue