summaryrefslogtreecommitdiff
path: root/cleopatre/application/managerd/inc/vs_mme.h
blob: e2470d5938fd11b1e9dc14d2e42833335871e215 (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
194
195
196
197
198
199
200
201
202
203
/*
 * cleopatre/application/managerd/inc/vs_mme.h
 *
 * (C) Copyright 2009 SPiDCOM Technologies
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */
#ifndef VS_MME_H
#define VS_MME_H

#include "libmme.h"
#include "managerd.h"
#include "bridge.h"

#define SPC300_ID 0x0001
#define PLC_VERSION_PATH "/proc/net/plc/version"
#define FIRMWARE_LABEL "PLC Firmware"

#define MME_RESULT_SUCCESS 0
#define MME_RESULT_FAILURE 1
#define MME_RESULT_TIMEOUT 2
#define MME_RESULT_BAD_IDX 2

#define MAX_NVRAM_BLK      64

/** if function fwrite failed during update, retry flash write */
#define FLASH_RETRY_COUNT 2

/** tftp update action **/
#define TFTP_UPDATE_ACTION_NONE    "0"

/** tftp update status **/
#define TFTP_UPDATE_SUCCESS        "2"
#define TFTP_UPDATE_FAILED         "3"

typedef struct {
    uint8_t oui[3];
    uint8_t result;
    uint16_t device_id;
    uint8_t current_image_index;
    uint8_t applicative_version[16];
    uint8_t av_stack_version[64];
    uint8_t applicative_alternate[16];
} __attribute__ ((__packed__)) vs_get_version_cnf_t;

typedef enum {
    ETH_STATS_COMMAND_GET = 0,
    ETH_STATS_COMMAND_RESET,
    ETH_STATS_COMMAND_NB
} vs_eth_stats_command_t;

typedef struct {
    uint8_t oui[3];
    uint8_t command;
} __attribute__ ((__packed__)) vs_eth_stats_req_t;

typedef struct {
    uint8_t oui[3];
    uint8_t result;
} __attribute__ ((__packed__)) vs_reset_cnf_t;

typedef struct {
    uint8_t oui[3];
    uint8_t result;
} __attribute__ ((__packed__)) vs_factory_cnf_t;

typedef struct {
    uint8_t oui[3];
    uint8_t result;
    uint32_t rx_bytes_low;
    uint32_t rx_bytes_high;
    uint32_t rx_packets_low;
    uint32_t rx_packets_high;
    uint32_t rx_errors;
    uint32_t rx_dropped;
    uint32_t rx_overruns;
    uint32_t rx_frames;
    uint32_t tx_bytes_low;
    uint32_t tx_bytes_high;
    uint32_t tx_packets_low;
    uint32_t tx_packets_high;
    uint32_t tx_errors;
    uint32_t tx_dropped;
    uint32_t tx_fifo;
    uint32_t tx_collisions;
    uint32_t tx_carrier;
} __attribute__ ((__packed__)) vs_eth_stats_cnf_t;

typedef struct {
    uint8_t oui[3];
    uint8_t index;
} __attribute__ ((__packed__)) vs_get_nvram_req_t;

typedef struct {
    uint8_t oui[3];
    uint8_t result;
    uint8_t index;
    uint8_t data[1024];
} __attribute__ ((__packed__)) vs_get_nvram_cnf_t;

typedef struct {
    uint8_t oui[3];
    uint8_t protocol;
    uint8_t version_id[16];
    uint32_t arch;
    uint32_t type;
    uint8_t board_type[32];
    uint8_t file[LIBSPID_UPDATE_FILE_STR_MAX_LEN];
    uint8_t server_ip[LIBSPID_IP_STR_MAX_LEN];
    uint8_t server_port[LIBSPID_UPDATE_PORT_STR_MAX_LEN];
    uint8_t md5_sum[MD5_DIGEST_LENGTH];
} __attribute__ ((__packed__)) vs_update_start_req_t;

typedef struct {
    uint8_t oui[3];
    uint8_t status;
} __attribute__ ((__packed__)) vs_update_start_cnf_t;

typedef struct {
    uint8_t oui[3];
    uint32_t id;
    uint32_t len;
    uint8_t data[LIBSPID_TRANSFER_MAX_SLICE];
} __attribute__ ((__packed__)) vs_update_transfer_req_t;

typedef struct {
    uint8_t oui[3];
    uint8_t status;
    uint32_t id;
} __attribute__ ((__packed__)) vs_update_transfer_cnf_t;

typedef struct {
    uint8_t oui[3];
    uint8_t md5_sum[MD5_DIGEST_LENGTH];
} __attribute__ ((__packed__)) vs_update_end_req_t;

typedef struct {
    uint8_t oui[3];
    uint8_t status;
} __attribute__ ((__packed__)) vs_update_end_cnf_t;

typedef struct {
    uint8_t oui[3];
    uint8_t status;
} __attribute__ ((__packed__)) vs_update_end_ind_t;

struct firmware_slice {
    uint8_t slice[LIBSPID_TRANSFER_MAX_SLICE];
    uint32_t size;
    struct firmware_slice *next;
};

typedef struct firmware_slice firmware_slice_t;

typedef struct {
    int lock;
    int next_blk_id;
    int bsize;
    long fsize;
    int flash_sector;
    FILE *fp;
    firmware_slice_t *head;
    firmware_slice_t *curr;
    char mtd_name[32];
    pthread_t timer;
    pthread_t writer;
    pthread_mutex_t mutex;
    int exit_timer;
    int exit_writer;
    int nb_img;
    unsigned char mac[ETH_ALEN];
    int protocol;
    int tftp_write;
} __attribute__ ((__packed__)) update_ctx_t;

extern enum bridge_status vs_mme_get_version (struct managerd_ctx *ctx, MME_t *request, MME_t * confirm, int len);
extern enum bridge_status vs_mme_eth_stats (struct managerd_ctx *ctx, MME_t *request, MME_t * confirm, int len);
extern enum bridge_status vs_mme_reset (struct managerd_ctx *ctx, MME_t *request, MME_t *confirm, int len);
extern enum bridge_status vs_mme_reset_handler (struct managerd_ctx *ctx, MME_t *request, MME_t * confirm, int len);
extern enum bridge_status vs_mme_factory (struct managerd_ctx *ctx,
                                          MME_t *request, MME_t *confirm,
                                          int len);
extern enum bridge_status vs_mme_update_start (struct managerd_ctx *ctx, MME_t *request, MME_t *confirm, int len);
extern enum bridge_status vs_mme_update_transfer (struct managerd_ctx *ctx, MME_t *request, MME_t *confirm, int len);
extern enum bridge_status vs_mme_update_end (struct managerd_ctx *ctx, MME_t *request, MME_t *confirm, int len);
extern enum bridge_status vs_mme_tftp_update_end_recv_indication (struct managerd_ctx *ctx, MME_t *request, MME_t *confirm, int len);
enum bridge_status
vs_mme_get_nvram (struct managerd_ctx *ctx, MME_t *request,
                  MME_t *confirm, int len);
#endif /* VS_MME_H */