summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cleopatre/application/libspid/inc/defs.h7
-rw-r--r--cleopatre/application/spidapp/inc/spidapp.h51
-rw-r--r--cleopatre/application/spidapp/src/spidapp.c403
-rw-r--r--cleopatre/devkit/doc/cleopatre_spidapp_specs.odtbin108074 -> 107050 bytes
4 files changed, 325 insertions, 136 deletions
diff --git a/cleopatre/application/libspid/inc/defs.h b/cleopatre/application/libspid/inc/defs.h
index b087e0d82c..e6ac7d009d 100644
--- a/cleopatre/application/libspid/inc/defs.h
+++ b/cleopatre/application/libspid/inc/defs.h
@@ -45,9 +45,14 @@
#define LIBSPID_SECU_PBKDF1_ITERATION 1000
/* LIBSPID_HPAV_CONF_PATH */
+/** Network PassWord */
+#define LIBSPID_HPAV_CONF_NPW_DEFAULT "HomePlugAV0123"
+#define LIBSPID_HPAV_CONF_NPW_MIN_LEN 8
+#define LIBSPID_HPAV_CONF_NPW_ADVISED_MIN_LEN 24
+#define LIBSPID_HPAV_CONF_NPW_MAX_LEN 64
/** Network Management Key */
#define LIBSPID_HPAV_CONF_NMK_STR_LEN 64
-#define LIBSPID_HPAV_CONF_NMK_BIN_LEN 16
+#define LIBSPID_HPAV_CONF_NMK_BIN_LEN LIBSPID_SECU_OUTPUT_KEY_SIZE
/** Network IDentifier */
#define LIBSPID_HPAV_CONF_NID_STR_LEN 32
#define LIBSPID_HPAV_CONF_NID_BIN_LEN 7
diff --git a/cleopatre/application/spidapp/inc/spidapp.h b/cleopatre/application/spidapp/inc/spidapp.h
index 26abdf5f16..ba26267b39 100644
--- a/cleopatre/application/spidapp/inc/spidapp.h
+++ b/cleopatre/application/spidapp/inc/spidapp.h
@@ -22,11 +22,50 @@
#ifndef SPIDAPP_H
#define SPIDAPP_H
-#define OUI_SPIDCOM "\x00\x13\xd7"
-#define IFNAME_LO "lo"
-#define NPW_DEFAULT "HomePlugAV0123"
-#define NPW_MIN_LEN 8
-#define NPW_ADVISED_MIN_LEN 24
-#define NPW_MAX_LEN 64
+#define NAME_CONFIG "config"
+#define NAME_SNIFFER "sniffer"
+#define NAME_HELP "help"
+
+#define USAGE_CONFIG \
+ "config: configure a spidcom system and save its configuration in flash memory\n" \
+ "\t-c --cco-preferred <yes|no>\n" \
+ "\t-w --was-cco <yes|no>\n" \
+ "\t-p --npw <network_password>\n" \
+ "\t\tcreate a new nmk from a human-friendly network password\n" \
+ "\t-n --nid <network_identifier|none>\n" \
+ "\t-s --sl <hs|sc>\n" \
+ "\t-u --user-hfid <user_human_friendly_identifier>\n" \
+ "\t-a --avln-hfid <av_logical_network_human_friendly_identifier>\n"
+
+#define USAGE_SNIFFER \
+ "sniffer: activate/deactivate sniffing of mme-s\n" \
+ "\t-a --mac <destination_mac_address>\n" \
+ "\t-m --mode <8_bits_field>\n" \
+ "\t\tbit 0 (lsb): mme tx\n" \
+ "\t\tbit 1: mme rx\n" \
+ "\t\tbit 2: beacon tx\n" \
+ "\t\tbit 3: beacon rx\n" \
+ "\t\tbit 4: -\n" \
+ "\t\tbit 5: fc rx\n" \
+ "\t\tbit 6: -\n" \
+ "\t\tbit 7 (msb): mpdu content rx\n"
+
+#define USAGE_HELP \
+ "help: current help listing mandatory and optional command line arguments\n"
+
+struct cmd_entry
+{
+ char *name;
+ unsigned int arg_nb;
+ char *usage;
+ int (*cmd) (struct cmd_entry *desc, int argc, char **argv);
+};
+
+int
+cmd_config (struct cmd_entry *cmd_entry, int argc, char **argv);
+int
+cmd_sniffer (struct cmd_entry *cmd_entry, int argc, char **argv);
+int
+cmd_help (struct cmd_entry *cmd_entry, int argc, char **argv);
#endif /* SPIDAPP_H */
diff --git a/cleopatre/application/spidapp/src/spidapp.c b/cleopatre/application/spidapp/src/spidapp.c
index 1a6961715a..86e426a0df 100644
--- a/cleopatre/application/spidapp/src/spidapp.c
+++ b/cleopatre/application/spidapp/src/spidapp.c
@@ -33,126 +33,271 @@
#include <net/if.h>
#include <net/ethernet.h>
#include <errno.h>
+
#include "libspid.h"
#include "libmme.h"
#include "spidapp.h"
-#define USAGE_NMK \
- "nmk: create a new NMK from a human friendly network password\n" \
- " --npw <network password>\n" \
- " --file <config file>\n"
-
-#define USAGE_SNIFFER \
- "sniffer: put the AV stack in sniffer mode\n"\
- " --mac <dst mac addr>\n" \
- " --mode <mode bitfield>\n" \
- " 0: disable all\n" \
- " 1: MME Tx\n" \
- " 2: MME Rx\n" \
- " 4: Beacon Tx\n" \
- " 8: Beacon Rx\n" \
- " 32: FC Rx\n" \
- " 128: MPDU Rx\n"
-
-struct cmd_entry {
- char *name;
- unsigned int arg_nb;
- char *usage;
- int (*cmd)(struct cmd_entry *desc, int argc, char **argv);
+struct cmd_entry cmd_table[] =
+{
+ {NAME_CONFIG, required_argument, USAGE_CONFIG, cmd_config},
+ {NAME_SNIFFER, required_argument, USAGE_SNIFFER, cmd_sniffer},
+ {NAME_HELP, no_argument, USAGE_HELP, cmd_help},
+ {NULL, 0, NULL, NULL},
};
-static void print_usage (struct cmd_entry *cmd_entry);
-static void binary_to_string (const unsigned char *binary, int binary_len, char *string)
-{
- int i;
- for(i = 0; i < binary_len; i++)
- {
- sprintf (string + i * 2, "%02x", binary[i]);
- }
-}
+/*******************************************************************************
+ * config command: configure a SPiDCOM system
+ * (don't forget to save the modified configuration file in flash memory).
+ ******************************************************************************/
-/******************************************************
- * NMK command: create a NMK from a NPW
- * (don't forget to save the modified hpav.conf file)
- ****************************************************/
-int cmd_nmk (struct cmd_entry *cmd_entry, int argc, char **argv)
+int
+cmd_config (struct cmd_entry *cmd_entry, int argc, char **argv)
{
- int c = 0, i;
- int opt_index = 0;
- char config_file[256];
- char npw[64];
- char nmk[LIBSPID_SECU_OUTPUT_KEY_SIZE], nmk_str[64];
- struct option long_opts[] = {
- { "npw", required_argument, NULL, 'n' },
- { "file", required_argument, NULL, 'f' },
+ libspid_boolean_t save_and_warn = LIBSPID_FALSE;
+ int c = 0, i = 0, opt_index = 0;
+ char npw[LIBSPID_HPAV_CONF_NPW_MAX_LEN] = {0},
+ nmk_bin[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0},
+ nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN] = {0};
+
+ struct option long_opts[] =
+ {
+ {"cco-preferred", required_argument, NULL, 'c'},
+ {"was-cco", required_argument, NULL, 'w'},
+ {"npw", required_argument, NULL, 'p'},
+ {"nid", required_argument, NULL, 'n'},
+ {"sl", required_argument, NULL, 's'},
+ {"user-hfid", required_argument, NULL, 'u'},
+ {"avln-hfid", required_argument, NULL, 'a'},
+ {"help", no_argument, NULL, 'h'},
};
- memset (npw, '\0', sizeof(npw));
- memset (config_file, '\0', sizeof(config_file));
- strcpy (config_file, LIBSPID_HPAV_CONF_PATH);
- strcpy (npw, NPW_DEFAULT);
- while( ( c = getopt_long_only(argc, argv, "", long_opts, &opt_index) ) != -1 )
+ strcpy (npw, LIBSPID_HPAV_CONF_NPW_DEFAULT);
+
+ while (-1 != (c = getopt_long_only (argc, argv, "c:w:p:n:s:u:a:h:",
+ long_opts, &opt_index)))
{
- switch(c)
+ switch (c)
{
- case 'n':
- if ((strlen(optarg) >= NPW_MIN_LEN) && (strlen(optarg) <= NPW_MAX_LEN))
- {
- if (strlen(optarg) <= NPW_ADVISED_MIN_LEN)
+ case 'c':
+ if (!strcmp (LIBSPID_VALUE_BOOLEAN_FALSE, optarg)
+ || !strcmp (LIBSPID_VALUE_BOOLEAN_TRUE, optarg))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item \
+ (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, optarg))
+ {
+ printf ("%s: libspid config write item error\n",
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED);
+ return -1;
+ }
+ printf ("%s: updated\n",
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED);
+ }
+ else
{
- printf ("The password may not be secure\n");
+ printf ("%s: argument error\n",
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED);
+ return -1;
}
- for (i = 0; i<strlen(optarg); i++)
+ save_and_warn = LIBSPID_TRUE;
+ break;
+ case 'w':
+ if (!strcmp (LIBSPID_VALUE_BOOLEAN_FALSE, optarg)
+ || !strcmp (LIBSPID_VALUE_BOOLEAN_TRUE, optarg))
{
- if ((optarg[i] < 32) || (optarg[i] > 127))
+ if (LIBSPID_SUCCESS != libspid_config_write_item \
+ (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO, optarg))
{
- printf ("Network Password must use characters from ASCII[32] to ASCII[127]\n");
- return (-1);
+ printf ("%s: libspid config write item error\n",
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO);
+ return -1;
}
+ printf ("%s: updated\n",
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO);
}
- strcpy (npw, optarg);
- }
- else
- {
- printf ("Network Password cannot be created using less than 8 or more than 64 characters\n");
- return (-1);
- }
- break;
- case 'f':
- strncpy (config_file, optarg, sizeof(config_file) - 1);
- break;
- default:
- print_usage (cmd_entry);
- return (-1);
+ else
+ {
+ printf ("%s: argument error\n",
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO);
+ return -1;
+ }
+ save_and_warn = LIBSPID_TRUE;
+ break;
+ case 'p':
+ if ((LIBSPID_HPAV_CONF_NPW_MIN_LEN <= strlen (optarg))
+ && (LIBSPID_HPAV_CONF_NPW_MAX_LEN >= strlen(optarg)))
+ {
+ if (LIBSPID_HPAV_CONF_NPW_ADVISED_MIN_LEN >= strlen(optarg))
+ {
+ printf ("NPW: may not be secure\n");
+ }
+ for (i = 0; i < strlen (optarg); i++)
+ {
+ if ((32 > optarg[i]) || (127 < optarg[i]))
+ {
+ printf ("NPW: must use characters from ASCII[32] to ASCII[127]\n");
+ return -1;
+ }
+ }
+ strcpy (npw, optarg);
+ }
+ else
+ {
+ printf ("NPW: cannot be created using less than 8 or more than 64 characters\n");
+ return -1;
+ }
+ if ((LIBSPID_SUCCESS != libspid_secu_pbkdf1 (npw, strlen (npw),
+ LIBSPID_SECU_SALT_TYPE_NMK, LIBSPID_SECU_PBKDF1_ITERATION,
+ nmk_bin, LIBSPID_SECU_OUTPUT_KEY_SIZE))
+ || (LIBSPID_SUCCESS != libspid_binary_to_hexstring (nmk_bin,
+ LIBSPID_HPAV_CONF_NMK_BIN_LEN, nmk_str))
+ || (LIBSPID_SUCCESS != libspid_config_write_item \
+ (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str)))
+ {
+ printf ("%s: libspid error\n",
+ LIBSPID_HPAV_CONF_LABEL_NMK);
+ return -1;
+ }
+ printf ("%s: updated (%s)\n",
+ LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str);
+ save_and_warn = LIBSPID_TRUE;
+ break;
+ case 'n':
+ if (strcmp (LIBSPID_VALUE_NONE, optarg))
+ {
+ if (LIBSPID_HPAV_CONF_NID_STR_LEN >= strlen (optarg))
+ {
+ for (i = 0; i < strlen (optarg); i++)
+ {
+ if (!isxdigit (optarg[i]))
+ {
+ printf ("%s: argument error\n",
+ LIBSPID_HPAV_CONF_LABEL_NID);
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ printf ("%s: argument error\n",
+ LIBSPID_HPAV_CONF_LABEL_NID);
+ return -1;
+ }
+ }
+ if (LIBSPID_SUCCESS != libspid_config_write_item \
+ (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_NID, optarg))
+ {
+ printf ("%s: libspid config write item error\n",
+ LIBSPID_HPAV_CONF_LABEL_NID);
+ return -1;
+ }
+ printf ("%s: updated\n",
+ LIBSPID_HPAV_CONF_LABEL_NID);
+ save_and_warn = LIBSPID_TRUE;
+ break;
+ case 's':
+ if (!strcmp (LIBSPID_HPAV_CONF_VALUE_SL_SC, optarg)
+ || !strcmp (LIBSPID_HPAV_CONF_VALUE_SL_HS, optarg))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item \
+ (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_SL, optarg))
+ {
+ printf ("%s: libspid config write item error\n",
+ LIBSPID_HPAV_CONF_LABEL_SL);
+ return -1;
+ }
+ }
+ else
+ {
+ printf ("%s: argument error\n",
+ LIBSPID_HPAV_CONF_LABEL_SL);
+ return -1;
+ }
+ printf ("%s: updated\n",
+ LIBSPID_HPAV_CONF_LABEL_SL);
+ save_and_warn = LIBSPID_TRUE;
+ break;
+ case 'u':
+ if (LIBSPID_HPAV_CONF_HFID_MAX_LEN >= strlen (optarg))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item \
+ (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID, optarg))
+ {
+ printf ("%s: libspid config write item error\n",
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID);
+ return -1;
+ }
+ }
+ else
+ {
+ printf ("%s: argument error\n",
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID);
+ return -1;
+ }
+ printf ("%s: updated\n",
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID);
+ save_and_warn = LIBSPID_TRUE;
+ break;
+ case 'a':
+ if (LIBSPID_HPAV_CONF_HFID_MAX_LEN >= strlen (optarg))
+ {
+ if (LIBSPID_SUCCESS != libspid_config_write_item \
+ (LIBSPID_HPAV_CONF_PATH,
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, optarg))
+ {
+ printf ("%s: libspid config write item error\n",
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID);
+ return -1;
+ }
+ }
+ else
+ {
+ printf ("%s: argument error\n",
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID);
+ return -1;
+ }
+ printf ("%s: updated\n",
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID);
+ save_and_warn = LIBSPID_TRUE;
+ break;
+ case 'h':
+ default:
+ printf ("%s", cmd_entry->usage);
+ return -1;
}
-
}
- libspid_secu_pbkdf1 (npw, strlen (npw), LIBSPID_SECU_SALT_TYPE_NMK, LIBSPID_SECU_PBKDF1_ITERATION, nmk, LIBSPID_SECU_OUTPUT_KEY_SIZE);
- binary_to_string (nmk, LIBSPID_SECU_OUTPUT_KEY_SIZE, nmk_str);
- libspid_config_write_item (config_file, LIBSPID_HPAV_CONF_LABEL_NMK, nmk_str);
- printf ("NMK(%s): '%s'\n", npw, nmk_str);
-
- /* hpav.conf save is needed */
- libspid_system_save_file (LIBSPID_HPAV_CONF_PATH);
-
- /* plc daemon needs to be informed */
- if (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(),
- LIBSPID_HPAV_CONF_PATH))
- {
- return -1;
- }
+ if (LIBSPID_TRUE == save_and_warn)
+ {
+ /* save hpav.conf and inform plc daemon */
+ if ((LIBSPID_SUCCESS != libspid_system_save_file (LIBSPID_HPAV_CONF_PATH))
+ || (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(),
+ LIBSPID_HPAV_CONF_PATH)))
+ {
+ printf ("%s: libspid system error\n", LIBSPID_HPAV_CONF_PATH);
+ return -1;
+ }
+ }
- return 0;
+ return 0;
}
-/****************************************************************
+
+/*******************************************************************************
* sniffer command: set the HPAV sniffer in sniff mode.
* The final host target mac-address of sniff packet must be provided
* else packets will be transmitted in broadcast mode
- ***************************************************************/
-int cmd_sniffer (struct cmd_entry *cmd_entry, int argc, char **argv)
+ ******************************************************************************/
+
+int
+cmd_sniffer (struct cmd_entry *cmd_entry, int argc, char **argv)
{
int sock;
struct sockaddr_ll sll;
@@ -165,21 +310,24 @@ int cmd_sniffer (struct cmd_entry *cmd_entry, int argc, char **argv)
MME_t *mme_hdr;
int pkt_len, len;
- struct option long_opts[] = {
- { "mac", required_argument, NULL, 'm' },
- { "mode", required_argument, NULL, 'n' },
+ struct option long_opts[] =
+ {
+ {"mac", required_argument, NULL, 'a'},
+ {"mode", required_argument, NULL, 'm'},
+ {"help", no_argument, NULL, 'h'},
};
/* set default src mac to broadcast */
memset (mac_src, '\xff', ETH_ALEN);
- while( ( c = getopt_long_only(argc, argv, "", long_opts, &opt_index) ) != -1 )
+ while (-1 != (c = getopt_long_only (argc, argv, "a:m:h:", long_opts,
+ &opt_index)))
{
switch(c)
{
case 'm':
if(libspid_mac_str_to_bin (optarg, mac_src) != LIBSPID_SUCCESS)
{
- print_usage (cmd_entry);
+ printf ("%s", cmd_entry->usage);
return (-1);
}
break;
@@ -187,12 +335,13 @@ int cmd_sniffer (struct cmd_entry *cmd_entry, int argc, char **argv)
mode = atoi (optarg);
if(mode & ~0xaf)
{
- print_usage (cmd_entry);
+ printf ("%s", cmd_entry->usage);
return (-1);
}
break;
+ case 'h':
default:
- print_usage (cmd_entry);
+ printf ("%s", cmd_entry->usage);
return (-1);
}
}
@@ -208,7 +357,7 @@ int cmd_sniffer (struct cmd_entry *cmd_entry, int argc, char **argv)
memset(&ifr, 0x0, sizeof(ifr));
/* First Get the Interface Index */
- strcpy(ifr.ifr_name, IFNAME_LO);
+ strcpy(ifr.ifr_name, MME_IFACE_LOOPBACK);
if ((ioctl(sock, SIOCGIFINDEX, &ifr)) < 0)
{
perror("Error getting plc0 interface index");
@@ -252,59 +401,55 @@ int cmd_sniffer (struct cmd_entry *cmd_entry, int argc, char **argv)
return 0;
}
-struct cmd_entry cmd_table[] = {
- { "nmk", 1, USAGE_NMK, cmd_nmk },
- { "sniffer", 1, USAGE_SNIFFER, cmd_sniffer },
- { NULL, 0, NULL, NULL },
-};
-static void print_usage (struct cmd_entry *cmd_entry)
+/*******************************************************************************
+ * help command: print usage.
+ ******************************************************************************/
+
+int
+cmd_help (struct cmd_entry *cmd_entry, int argc, char **argv)
{
- printf ("Usage: spidapp <command> [options]\n");
+ int i = 0;
+
printf ("Utility tool for spc300\n");
- if(cmd_entry == NULL)
- {
- struct cmd_entry *tmp_entry = cmd_table;
- int i = 0;
- printf ("Command list:\n");
- while(cmd_table[i].name != NULL)
- {
- printf ("%s", cmd_table[i].usage);
- i++;
- }
- }
- else
+ printf ("Usage: spidapp <command> [options]\n");
+ printf ("Command list:\n");
+ while (NULL != cmd_table[i].name)
{
- printf ("%s", cmd_entry->usage);
+ printf ("%s", cmd_table[i].usage);
+ i++;
}
}
-int main (int argc, char **argv)
+
+int
+main (int argc, char **argv)
{
- int cmd_index = 0;
- int argv_index = 0;
+ int cmd_index = 0, argv_index = 0;
struct cmd_entry *cmd_entry;
+
if (argc < 2)
{
- print_usage (NULL);
+ cmd_help (NULL, 0, NULL);
exit (1);
}
argc--;
argv_index++;
- while(cmd_table[cmd_index].name != NULL)
+ while (NULL != cmd_table[cmd_index].name)
{
- if(!strcmp (cmd_table[cmd_index].name, argv[argv_index]))
+ if (!strcmp (cmd_table[cmd_index].name, argv[argv_index]))
break;
cmd_index++;
}
- if(NULL == cmd_table[cmd_index].name)
+
+ if (NULL == cmd_table[cmd_index].name)
{
- print_usage (NULL);
+ cmd_help (NULL, 0, NULL);
exit (1);
}
- if((cmd_table[cmd_index].cmd) (cmd_table + cmd_index, argc, argv + argv_index) < 0)
+ if (0 > (cmd_table[cmd_index].cmd) (cmd_table + cmd_index, argc, argv + argv_index))
{
exit (1);
}
diff --git a/cleopatre/devkit/doc/cleopatre_spidapp_specs.odt b/cleopatre/devkit/doc/cleopatre_spidapp_specs.odt
index 077529b219..5c3cbb5e5e 100644
--- a/cleopatre/devkit/doc/cleopatre_spidapp_specs.odt
+++ b/cleopatre/devkit/doc/cleopatre_spidapp_specs.odt
Binary files differ