Skip to content
Snippets Groups Projects
Commit 1df5b798 authored by f4grx's avatar f4grx
Browse files

progress on config app

parent 54abe12c
No related branches found
No related tags found
No related merge requests found
......@@ -38,8 +38,9 @@
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
......@@ -82,6 +83,25 @@ int config_list(void)
printf("%s\n", inet_ntoa(val));
}
}
else if(type == EECONFIG_TYPE_BYTE)
{
uint8_t val;
ret = hn70ap_eeconfig_getbyte(name, &val);
if(ret == OK)
{
printf("%d (0x%02X)\n", val, val);
}
}
else if(type == EECONFIG_TYPE_CALL)
{
char val[9];
memset(val, 0, sizeof(val));
ret = hn70ap_eeconfig_getcall(name, val);
if(ret == OK)
{
printf("%s\n", val);
}
}
if(ret != OK)
{
printf("<unreadable>\n");
......
......@@ -39,6 +39,7 @@
#include <nuttx/config.h>
#include <stdio.h>
#include <string.h>
#include <hn70ap/eeprom.h>
......@@ -48,8 +49,79 @@
* Public Functions
****************************************************************************/
int config_set(char *key, char *val)
int config_set(char *key, char *value)
{
return ERROR;
char name[16];
uint32_t type;
int ret;
/* Get config entry */
ret = hn70ap_eeconfig_describe(hn70ap_eeconfig_find(name), name, sizeof(name), &type);
if(ret != OK)
{
fprintf(stderr, "Config entry not found\n");
return ERROR;
}
if(type == EECONFIG_TYPE_BOOL)
{
bool val;
printf("Entry type is bool\n");
if(!strcmp(value, "true") ||
!strcmp(value, "True") ||
!strcmp(value, "TRUE") ||
!strcmp(value, "yes") ||
!strcmp(value, "Yes") ||
!strcmp(value, "YES") ||
!strcmp(value, "y") ||
!strcmp(value, "Y") ||
!strcmp(value, "1")
)
{
val = true;
}
else if(!strcmp(val, "false") ||
!strcmp(value, "False") ||
!strcmp(value, "FALSE") ||
!strcmp(value, "no") ||
!strcmp(value, "No") ||
!strcmp(value, "NO") ||
!strcmp(value, "n") ||
!strcmp(value, "N") ||
!strcmp(value, "0")
)
{
val = false;
}
else
{
printf("Unrecognized boolean value: %s\n",val);
return ERROR;
}
ret = hn70ap_eeconfig_setbool(name, val);
}
else if(type == EECONFIG_TYPE_IP)
{
in_addr_t val;
printf("Entry type is IPv4\n");
val = inet_aton(value);
ret = hn70ap_eeconfig_setip(name, val);
}
else if(type == EECONFIG_TYPE_CALL)
{
printf("Entry type is call\n");
}
else if(type == EECONFIG_TYPE_BYTE)
{
printf("Entry type is byte\n");
}
else
{
fprintf(stderr, "Config entry not found\n");
return ERROR;
}
return ret;
}
......@@ -7,6 +7,8 @@
#define EECONFIG_TYPE_BOOL 1 /* 8 bools mapped in 1 byte */
#define EECONFIG_TYPE_IP 2 /* 4 bytes */
#define EECONFIG_TYPE_CALL 3 /* 8 bytes */
#define EECONFIG_TYPE_BYTE 4 /* 1 byte */
/* Name of the EEPROM device */
......@@ -16,9 +18,18 @@
/* Initialize the EEPROM configuration management */
int hn70ap_eeconfig_init(bool *default_set);
int hn70ap_eeconfig_find(char *name);
int hn70ap_eeconfig_describe(int index, char *namebuf, int namebuflen, uint32_t *type);
int hn70ap_eeconfig_getbool(char *name, bool *value);
int hn70ap_eeconfig_getip(char *name, struct in_addr *value);
int hn70ap_eeconfig_getip (char *name, in_addr_t *value);
int hn70ap_eeconfig_getbyte(char *name, uint8_t *value);
int hn70ap_eeconfig_getcall(char *name, char *value);
int hn70ap_eeconfig_setbool(char *name, bool value);
int hn70ap_eeconfig_setip (char *name, in_addr_t value);
int hn70ap_eeconfig_setbyte(char *name, uint8_t value);
int hn70ap_eeconfig_setcall(char *name, char *value);
int hn70ap_eeprom_read (uint32_t addr, uint8_t *buf, uint32_t len);
int hn70ap_eeprom_write(uint32_t addr, uint8_t *buf, uint32_t len);
......
......@@ -67,13 +67,15 @@ struct param_s
const struct param_s eeconfig_params[] =
{
{"dhcp", EECONFIG_TYPE_BOOL, 1, 0x01}, /* 0x01 - 0x01 DHCP Client Enable */
/* 0x02 - 0x03 RFU for more network options */
{"ip" , EECONFIG_TYPE_IP , 4, 0}, /* 0x04 - 0x07 Static IP address to use if DHCP is not enabled */
{"mask", EECONFIG_TYPE_IP , 8, 0}, /* 0x08 - 0x0B Static IP mask to use if DHCP is not enabled */
{"gw" , EECONFIG_TYPE_IP , 12, 0}, /* 0x0C - 0x0F IP address of default gateway */
{"dns" , EECONFIG_TYPE_IP , 16, 0}, /* 0x10 - 0x13 IP address of DNS server (independent of DHCP enable)*/
/* 0x14 - 0x7F RFU for more network options */
{"dhcp", EECONFIG_TYPE_BOOL, 0x01, 0x01}, /* 0x01 - 0x01 DHCP Client Enable */
/* 0x02 - 0x03 RFU for more network options */
{"ip" , EECONFIG_TYPE_IP , 0x04, 0}, /* 0x04 - 0x07 Static IP address to use if DHCP is not enabled */
{"mask", EECONFIG_TYPE_IP , 0x08, 0}, /* 0x08 - 0x0B Static IP mask to use if DHCP is not enabled */
{"gw" , EECONFIG_TYPE_IP , 0x0C, 0}, /* 0x0C - 0x0F IP address of default gateway */
{"dns" , EECONFIG_TYPE_IP , 0x10, 0}, /* 0x10 - 0x13 IP address of DNS server (independent of DHCP enable)*/
{"call", EECONFIG_TYPE_CALL, 0x14, 0}, /* 0x14 - 0x1B HAM callsign, zero padded */
{"ssid", EECONFIG_TYPE_BYTE, 0x1C, 0}, /* 0x1C - 0x1C HAM Station ID */
/* 0x1D - 0x7F RFU for more options */
};
#define EECONFIG_PARAMS_COUNT (sizeof(eeconfig_params) / sizeof(eeconfig_params[0]))
......@@ -98,6 +100,8 @@ int hn70ap_eeconfig_init(bool *default_set)
if( buf != HN70AP_CONFIG_INSTALLED)
{
*default_set = true;
/* Set network address mode to DHCP */
/* Clean network address and mask */
buf = HN70AP_CONFIG_INSTALLED;
hn70ap_eeprom_write(0, &buf, 1);
}
......@@ -172,7 +176,7 @@ int hn70ap_eeconfig_describe(int index, char *namebuf, int namebuflen, uint32_t
}
/*----------------------------------------------------------------------------*/
static int hn70ap_eeconfig_find(char *name)
int hn70ap_eeconfig_find(char *name)
{
int i;
for(i = 0; i < EECONFIG_PARAMS_COUNT; i++)
......@@ -211,7 +215,7 @@ int hn70ap_eeconfig_getbool(char *name, bool *value)
}
/*----------------------------------------------------------------------------*/
int hn70ap_eeconfig_getip(char *name, struct in_addr *value)
int hn70ap_eeconfig_getip(char *name, in_addr_t *value)
{
int index = hn70ap_eeconfig_find(name);
int ret;
......@@ -233,3 +237,149 @@ int hn70ap_eeconfig_getip(char *name, struct in_addr *value)
return OK;
}
/*----------------------------------------------------------------------------*/
int hn70ap_eeconfig_getbyte(char *name, uint8_t *value)
{
int index = hn70ap_eeconfig_find(name);
int ret;
if(index < 0)
{
return ERROR;
}
if(eeconfig_params[index].type != EECONFIG_TYPE_BYTE)
{
return ERROR;
}
ret = hn70ap_eeprom_read(eeconfig_params[index].addr, value, 1);
if(ret != OK)
{
return ERROR;
}
return OK;
}
/*----------------------------------------------------------------------------*/
int hn70ap_eeconfig_getcall(char *name, char *value)
{
int index = hn70ap_eeconfig_find(name);
int ret;
if(index < 0)
{
return ERROR;
}
if(eeconfig_params[index].type != EECONFIG_TYPE_CALL)
{
return ERROR;
}
ret = hn70ap_eeprom_read(eeconfig_params[index].addr, (uint8_t*)value, 8);
if(ret != OK)
{
return ERROR;
}
return OK;
}
/*----------------------------------------------------------------------------*/
int hn70ap_eeconfig_setbool(char *name, bool value)
{
int index = hn70ap_eeconfig_find(name);
int ret;
uint8_t buf;
if(index < 0)
{
return ERROR;
}
if(eeconfig_params[index].type != EECONFIG_TYPE_BOOL)
{
return ERROR;
}
ret = hn70ap_eeprom_read(eeconfig_params[index].addr, &buf, 1);
if(ret != OK)
{
return ERROR;
}
if(value)
{
buf |= eeconfig_params[index].mask;
}
else
{
buf &= ~eeconfig_params[index].mask;
}
ret = hn70ap_eeprom_write(eeconfig_params[index].addr, &buf, 1);
if(ret != OK)
{
return ERROR;
}
return OK;
}
/*----------------------------------------------------------------------------*/
int hn70ap_eeconfig_setip(char *name, in_addr_t value)
{
int index = hn70ap_eeconfig_find(name);
int ret;
if(index < 0)
{
return ERROR;
}
if(eeconfig_params[index].type != EECONFIG_TYPE_IP)
{
return ERROR;
}
ret = hn70ap_eeprom_write(eeconfig_params[index].addr, (uint8_t*)&value, 4);
if(ret != OK)
{
return ERROR;
}
return OK;
}
/*----------------------------------------------------------------------------*/
int hn70ap_eeconfig_setbyte(char *name, uint8_t value)
{
int index = hn70ap_eeconfig_find(name);
int ret;
if(index < 0)
{
return ERROR;
}
if(eeconfig_params[index].type != EECONFIG_TYPE_BYTE)
{
return ERROR;
}
ret = hn70ap_eeprom_write(eeconfig_params[index].addr, &value, 1);
if(ret != OK)
{
return ERROR;
}
return OK;
}
/*----------------------------------------------------------------------------*/
int hn70ap_eeconfig_setcall(char *name, char *value)
{
int index = hn70ap_eeconfig_find(name);
int ret;
if(index < 0)
{
return ERROR;
}
if(eeconfig_params[index].type != EECONFIG_TYPE_CALL)
{
return ERROR;
}
ret = hn70ap_eeprom_write(eeconfig_params[index].addr, (uint8_t*)value, 8);
if(ret != OK)
{
return ERROR;
}
return OK;
}
......@@ -67,7 +67,6 @@ int update_write_start(struct update_context_s *ctx)
/*----------------------------------------------------------------------------*/
int update_write(struct update_context_s *ctx, uint8_t *buf, uint32_t len)
{
int retval = OK; //default will proceed with next packet after this one.
int room;
int off = 0;
int ret; /* ioctl return values */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment