summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcd/inc/plcd.h
blob: cd4738d30b813a403e49ddf50d27486bafbe96f3 (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
/* 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 <time.h>
#include <linux/netlink.h>

#include "mmtypes.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_MASK 0x0003

#define MME_RESULT_SUCCESS 0x00

#define PLCD_EVENT_REFRESH_TIMEOUT_MS 1000
#define PLCD_INIT_RETRIES 10

/* Interface name */
#define PLC_IFNAME  "plc0"

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;

/** NVRAM fields needed by plcd */
typedef struct
{
    unsigned char plc_address[6];
    char device_password[32];
    char product_name[64];
    char tonemask[192];
} plcd_nvram_t;

/** 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 */
    plcd_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;

/* Global handler on autoswitch timer. */
extern timer_t autoswitch_timer;
extern int autoswitch_en;
extern int autoswitch_timer_alive;

#define PLCD_AUTOSWITCH_TIMEOUT_SEC 60

void plcd_autoswitch_timer_init (void);
void plcd_autoswitch_image_update (void);

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 */