summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcd/inc/plcd.h
blob: d21e9bc8b6d8c153997cb00ec0bf21fe67cf4fa9 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* SPC300 bundle {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    devkit/plcd/inc/plcd.h
 * \brief   structures and defines of plcd
 * \ingroup plcd
 *
 *
 */
#ifndef PLCD_H
#define PLCD_H

#include <net/ethernet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdint.h>
#include <linux/netlink.h>

#include "nvram.h"

#define PLCD_ASSERT(condition) \
{ \
    if (!(condition)) \
    { \
        syslog (LOG_ERR, "%s: %d: %s: Assertion '%s' failed.", \
                __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(condition)); \
        abort(); \
    } \
}

#define MME_TYPE_DRV_STA_SET_MAC_ADDR   0xb000
#define MME_TYPE_DRV_STA_SET_CCO_PREF   0xb004
#define MME_TYPE_DRV_STA_SET_WAS_CCO    0xb008
#define MME_TYPE_DRV_STA_SET_SL         0xb014
#define MME_TYPE_DRV_STA_SET_M_STA_HFID 0xb018
#define MME_TYPE_DRV_STA_SET_U_STA_HFID 0xb01c
#define MME_TYPE_DRV_STA_SET_AVLN_HFID  0xb020
#define MME_TYPE_DRV_STA_SET_TONEMASK   0xb024
#define MME_TYPE_DRV_STA_MAC_START      0xb028
#define MME_TYPE_DRV_STA_MAC_STOP       0xb02c
#define MME_TYPE_DRV_STA_SC             0xb034
#define MME_TYPE_DRV_STA_STATUS         0xb03c
#define MME_TYPE_DRV_STA_SET_KEY        0xb040
#define MME_TYPE_DRV_STA_GET_KEY        0xb044
#define MME_TYPE_DRV_STA_SET_DAK        0xb048
#define MME_TYPE_DRV_STA_SET_CONFIG     0xb04c
#define MME_TYPE_DRV_STA_SET_MCAST_LIST 0xb054

#define MME_TYPE_REQ  0x0000
#define MME_TYPE_CNF  0x0001
#define MME_TYPE_IND  0x0002
#define MME_TYPE_RSP  0x0003
#define MME_TYPE_MASK 0x0003

#define MME_RESULT_SUCCESS 0x00

#define PLCD_EVENT_REFRESH_TIMEOUT_MS 1000
#define PLCD_INIT_RETRIES 10

typedef enum
{
    MME_DRV_STATUS_ASSOC_UNASSOCIATED = 0,
    MME_DRV_STATUS_ASSOC_ASSOCIATED,
    MME_DRV_STATUS_ASSOC_AUTHENTICATED,
    MME_DRV_STATUS_ASSOC_NB
} mme_drv_status_assoc_t;

typedef enum
{
    MME_DRV_STATUS_CCO_STATION = 0,
    MME_DRV_STATUS_CCO_PROXY,
    MME_DRV_STATUS_CCO_MAIN,
    MME_DRV_STATUS_CCO_NB
} mme_drv_status_cco_t;

typedef enum
{
    MME_DRV_SC_ADD = 0,
    MME_DRV_SC_JOIN,
    MME_DRV_SC_NB
} mme_drv_sc_t;

typedef enum
{
    MME_DRV_KEY_TYPE_NID = 0,
    MME_DRV_KEY_TYPE_SL,
    MME_DRV_KEY_TYPE_NB
} mme_drv_key_type_t;

typedef enum
{
    MME_DRV_KEY_SL_SC = 0,
    MME_DRV_KEY_SL_HS,
    MME_DRV_KEY_SL_NB
} mme_drv_key_sl_t;

static char *mme_drv_status_assoc_table[] =
{
    LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED,
    LIBSPID_HPAV_INFO_VALUE_STATUS_ASSOCIATED,
    LIBSPID_HPAV_INFO_VALUE_STATUS_AUTHENTICATED,
    NULL
};

static char *mme_drv_status_cco_table[] =
{
    LIBSPID_HPAV_INFO_VALUE_CCO_STATION,
    LIBSPID_HPAV_INFO_VALUE_CCO_PROXY,
    LIBSPID_HPAV_INFO_VALUE_CCO_MAIN,
    NULL
};

static char *mme_drv_key_sl_table[] =
{
    LIBSPID_HPAV_CONF_VALUE_SL_SC,
    LIBSPID_HPAV_CONF_VALUE_SL_HS,
    NULL
};



/** main context of plc daemon */ 
typedef struct
{
    /** full path of HPAV info file */
    char *hpav_info_path;
    /** full path of HPAV config file */
    char *hpav_conf_path;
    /** full path of internal config file */
    char *internal_conf_path;
    /** netlink socket descriptor for PLC driver comm */
    int plc_sock;
    /** plcd netlink address descriptor for PLC driver comm */
    struct sockaddr_nl plcd_addr;
    /** NVRAM structure */
    spc300_nvram_t *nvram;
    /** indicates if configuration files have to be saved in flash */
    libspid_boolean_t is_save_conf_needed;
    /** indicates if other processes have to be informed about files modifications */
    libspid_boolean_t is_warn_needed;
    /* hpav.conf last values */
    struct
    {
        /* CCo preference */
        libspid_boolean_t is_cco_preferred;
        /* CCo status at boot */
        libspid_boolean_t was_cco;
        /* NMK value */
        char nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN];
        /* NID value */
        char nid_str[LIBSPID_HPAV_CONF_NID_STR_LEN];
        /* SL value */
        char sl_str[LIBSPID_HPAV_CONF_SL_STR_MAX_LEN];
        /* user HFID value */
        char user_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
        /* AVLN HFID value */
        char avln_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
    } hpav_conf;
    /* hpav.info last values */
    libspid_hpav_info_t hpav_info;
    /** Last time the multicast info file was checked. */
    struct timespec mcast_last_check;

} plcd_ctx_t;

/* Global variable indicating if a SIGHUP signal occurred,
 * has been caught in plcd signal handler,
 * and has now to be processed. */
extern volatile sig_atomic_t is_process_signal_needed;

int plcd_send_recv_drv_mme (const plcd_ctx_t *ctx, const mme_ctx_t *request_ctx,
                            mme_ctx_t *confirm_ctx, mme_ctx_t *indication_ctx);

/**
 * Tell whether the multicast info file was updated since last check.
 * \param  ctx  The context;
 * \return  LIBSPID_TRUE, if the multicast info has been updated.
 *          LIBSPID_FALSE, if no update since last check.
 */
libspid_boolean_t plcd_multicast_info_updated (plcd_ctx_t *ctx);

/**
 * Process the multicast info.
 * \param  ctx  the plcd context.
 */
void plcd_multicast_process (plcd_ctx_t *ctx);

#endif /* PLCD_H */