summaryrefslogtreecommitdiff
path: root/cleopatre/application/libspid/inc/libspid.h
blob: ea2c6967df1b992ddb08bd0a31152c18012c59f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* 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 <stdlib.h> /** pid_t */
#include <signal.h> /** sigaction(), kill(), struct siginfo */

#include "spid_img_desc.h"
#include "nvram.h"
#include "label.h"
#include "openssl_sha256.h"
#include "path.h"
#include "defs.h"
#include "multicast_info.h"

#define LIBSPID_GET_BOOLEAN(array) ((array[0] == 'Y' || array[0] == 'y') ? \
    LIBSPID_TRUE : LIBSPID_FALSE)

/** 
 * boolean type used in Libspid functions definitions
 */ 
typedef enum
{
    LIBSPID_FALSE = 0,
    LIBSPID_TRUE = 1,
    LIBSPID_BOOLEAN_NB
} libspid_boolean_t;

/**
 * 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,
    /** an error specific to the processing done by the function.
     * More details may be provided in an other status returned by the function. */
    LIBSPID_ERROR_PROCESSING
} 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_STR_MAX_LEN];
    /** IP netmask in string format */
    unsigned char netmask[LIBSPID_IP_STR_MAX_LEN];
    /** broadcast address in string format */
    unsigned char broadcast[LIBSPID_IP_STR_MAX_LEN];
    /** gateway IP address in string format */
    unsigned char gateway[LIBSPID_IP_STR_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;

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;

typedef struct
{
    /* status value */
    char status[LIBSPID_HPAV_INFO_STATUS_MAX_LEN];
    /* CCo value */
    char cco[LIBSPID_HPAV_INFO_CCO_MAX_LEN];
    /* backup CCo value */
    libspid_boolean_t is_backup_cco;
    /* Simple Connect value */
    libspid_boolean_t is_sc;
    /* Simple Connect button value */
    libspid_boolean_t is_sc_button;
} libspid_hpav_info_t;

/** Signal handler. */
typedef void (*libspid_signal_handler_t) (int);

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_read_items (const char *filename, const char * const labels[], char *values[], const int buffers_len[], unsigned int count);
extern libspid_error_t libspid_config_write_item(const char *filename, const char *label, const char *value);
extern libspid_error_t libspid_config_write_items (const char *filename, const char * const labels[], const char * const values[], unsigned int count);
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_hexstring_to_binary (const char* hex_string, unsigned char *binary, unsigned int binary_length);
extern libspid_error_t libspid_binary_to_hexstring (const unsigned char *binary, unsigned int binary_length, char *hex_string);
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_get_index (const char *mtd_path, int *index);
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(spidcom_nvram_t *nvram);
extern libspid_error_t libspid_system_file_update_register (pid_t rx_pid, const char *filename, const libspid_signal_handler_t callback);
extern libspid_error_t libspid_system_file_update_unregister (pid_t rx_pid, const char *filename);
extern libspid_error_t libspid_system_file_update_is_registered (pid_t rx_pid, const char *filename, libspid_boolean_t *is_registered);
extern libspid_error_t libspid_system_file_update_warn (pid_t tx_pid, const char *filename);
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);

extern libspid_error_t
libspid_multicast_info_read_file (libspid_multicast_info_t *mcast_info,
                                  libspid_multicast_info_read_status_t *read_status);

extern libspid_error_t
libspid_multicast_info_write_file (libspid_multicast_info_t *mcast_info);

extern libspid_error_t
libspid_hpav_info_read_file (libspid_hpav_info_t *hpav_info);
libspid_error_t libspid_image_update_current_index(uint32_t   index,
                                                   const char *mtd_name);
#endif /* LIBSPID_H */