summaryrefslogtreecommitdiff
path: root/cleopatre/application/libspid/inc/libspid.h
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/application/libspid/inc/libspid.h')
-rw-r--r--cleopatre/application/libspid/inc/libspid.h145
1 files changed, 145 insertions, 0 deletions
diff --git a/cleopatre/application/libspid/inc/libspid.h b/cleopatre/application/libspid/inc/libspid.h
new file mode 100644
index 0000000000..29f354d573
--- /dev/null
+++ b/cleopatre/application/libspid/inc/libspid.h
@@ -0,0 +1,145 @@
+/* SPC300 bundle {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file application/libspid/inc/libspid.h
+ * \brief structures and function prototypes of libspid
+ * \defgroup libspid libspid : general purpose SPiDCOM library
+ *
+ */
+
+#ifndef LIBSPID_H
+#define LIBSPID_H
+
+#include <stdint.h>
+#include <assert.h>
+
+#include "spid_img_desc.h"
+#include "nvram.h"
+#include "label.h"
+#include "openssl_sha256.h"
+#include "path.h"
+
+/** size of buffer to manage ip address */
+#define LIBSPID_IP_MAX_LEN 16
+
+/** size of buffer to manage mac address */
+#define LIBSPID_MAC_STR_LEN 18
+
+#define LIBSPID_LINE_MAX_LEN 1024
+#define LIBSPID_KEY_MAX_LEN 63
+#define LIBSPID_ELT_MAX_NB 32
+#define LIBSPID_CONFIG_DELIMITER "="
+#define LIBSPID_FALSE 0
+#define LIBSPID_TRUE 1
+
+/**
+ * list of errors returned by libspid functions
+ */
+typedef enum {
+ LIBSPID_SUCCESS = 0,
+ /** bad input parameters */
+ LIBSPID_ERROR_PARAM,
+ /** not enough available space */
+ LIBSPID_ERROR_NO_SPACE,
+ /** item / data not found */
+ LIBSPID_ERROR_NOT_FOUND,
+ /** system error, see errno for more details */
+ LIBSPID_ERROR_SYSTEM,
+} libspid_error_t;
+
+/**
+ * IP mode of interface : static or DHCP
+ */
+typedef enum {
+ /** interface setting is static : configuration is given by the local config file */
+ LIBSPID_IP_MODE_STATIC,
+ /** interface setting is DHCP : configuration is given by a DHCP server */
+ LIBSPID_IP_MODE_DHCP,
+} libspid_ip_mode_t;
+
+/** structure to manage IP network data */
+typedef struct {
+ /** IP mode */
+ libspid_ip_mode_t mode;
+ /** IP address in string format */
+ unsigned char address[LIBSPID_IP_MAX_LEN];
+ /** IP netmask in string format */
+ unsigned char netmask[LIBSPID_IP_MAX_LEN];
+ /** broadcast address in string format */
+ unsigned char broadcast[LIBSPID_IP_MAX_LEN];
+ /** gateway IP address in string format */
+ unsigned char gateway[LIBSPID_IP_MAX_LEN];
+ /** MTU of interface */
+ unsigned int mtu;
+} libspid_ip_t;
+
+typedef enum {
+ LIBSPID_IMAGE_DESC_TYPE_0,
+ LIBSPID_IMAGE_DESC_TYPE_1,
+ LIBSPID_IMAGE_DESC_TYPE_CURRENT,
+ LIBSPID_IMAGE_DESC_TYPE_ALTERNATE,
+ LIBSPID_IMAGE_DESC_TYPE_NB
+} libspid_image_desc_type_t;
+
+typedef enum {
+ LIBSPID_IMAGE_SELECT_0,
+ LIBSPID_IMAGE_SELECT_1,
+ LIBSPID_IMAGE_SELECT_SWITCH,
+ LIBSPID_IMAGE_SELECT_NB
+} libspid_image_select_t;
+
+/** */
+typedef struct
+{
+ int nothing;
+} spc300_image_desc_t;
+
+#define LIBSPID_GET_BOOLEAN(array) ((array[0] == 'Y' || array[0] == 'y')?1:0)
+/** size of pbkdf1 salt */
+#define LIBSPID_SECU_SALT_SIZE 8
+/** max password size. */
+#define LIBSPID_SECU_PWD_SIZE_MAX 64
+/** SHA 256 size. */
+#define LIBSPID_SECU_SHA256_SIZE 32
+/** pbkdf1 generated key size */
+#define LIBSPID_SECU_OUTPUT_KEY_SIZE 16
+/** PBKDF1 iteration. */
+#define LIBSPID_SECU_PBKDF1_ITERATION 1000
+
+typedef enum {
+ LIBSPID_SECU_SALT_TYPE_NONE = 0,
+ LIBSPID_SECU_SALT_TYPE_DAK,
+ LIBSPID_SECU_SALT_TYPE_NMK,
+ LIBSPID_SECU_SALT_TYPE_NB
+} libspid_secu_salt_type_t;
+
+extern libspid_error_t libspid_config_read_item (const char *filename, const char *label, char *value, int buffer_len);
+extern libspid_error_t libspid_config_write_item(const char *filename, const char *label, const char *value);
+extern libspid_error_t libspid_config_read_line(const char *filename, const char* delimiters, char *key, unsigned int *elt_number, char *elt[], char *buffer, unsigned int buffer_len);
+extern libspid_error_t libspid_config_write_line(const char *filename, const char delimiter, const char *key, unsigned int elt_number, char *elt[]);
+extern libspid_error_t libspid_config_remove_line(const char *filename, const char *delimiters, const char *key);
+extern libspid_error_t libspid_mac_str_to_bin(const char *str, unsigned char *bin);
+extern libspid_error_t libspid_mac_bin_to_str(const unsigned char *bin, char *str);
+extern libspid_error_t libspid_image_get_desc(libspid_image_desc_type_t type, spidcom_image_desc_t *image_desc, char *mtd_name);
+extern libspid_error_t libspid_image_select(libspid_image_select_t select);
+extern libspid_error_t libspid_network_get_ip (const char *interface, libspid_ip_t *ip);
+extern libspid_error_t libspid_network_set_ip (const char *interface, const libspid_ip_t *ip);
+extern libspid_error_t libspid_network_get_mac (const char *interface, unsigned char *mac);
+extern libspid_error_t libspid_system_get_kernel_version(char *buffer, int buffer_len);
+extern libspid_error_t libspid_system_get_plc_version (char *buffer, const int buffer_len);
+extern libspid_error_t libspid_system_get_av_version (char *buffer, const int buffer_len);
+extern libspid_error_t libspid_system_get_uptime(unsigned int *total_s, unsigned int *idle_s);
+extern libspid_error_t libspid_system_get_meminfo(char *buffer, int buffer_len);
+extern void libspid_system_reboot(void);
+extern libspid_error_t libspid_system_save(void);
+extern libspid_error_t libspid_system_save_file(const char *filename);
+extern libspid_error_t libspid_system_factory(void);
+extern libspid_error_t libspid_system_get_nvram(spc300_nvram_t *nvram);
+extern libspid_error_t libspid_secu_pbkdf1 (const unsigned char input[], const unsigned int input_length, const libspid_secu_salt_type_t salt_type, const unsigned int it_count, unsigned char output[], unsigned int output_length);
+
+#endif /* LIBSPID_H */