summaryrefslogtreecommitdiff
path: root/cleopatre/tools/spidupd/spidupd_host.h
blob: 61a0cc8339826b68cd77a158e0780e561288781d (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
/*
 * tools/spidupd/spidupd_host.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 __SPIDUPD_HOST_H__
#define __SPIDUPD_HOST_H__

/** Message Management Entity header structure. */
struct MME_t
{
    /** Destination node. */
    unsigned char mme_dest[6];
    /** Source node. */
    unsigned char mme_src[6];
    /** 0x88e1 (iee assigned Ethertype). */
    unsigned short mtype;
    /** Management Message Version. */
    unsigned char mmv;
    /** Management Message Type. */
    unsigned short mmtype;
    /** Fragmentation Management Info. */
    unsigned short fmi;
} __attribute__ ((__packed__));
typedef struct MME_t MME_t;

/** Ethernet Type for MMEs. */
#define ETH_P_HPAV              0x88e1

/** MME header size (Homeplug AV). */
#define MME_HDR_SIZE            17

/** Max packet size. */
#define PKTSIZE                 1518

/** Max MME content size. */
#define MAX_MME_SIZE            (PKTSIZE - MME_HDR_SIZE)

/** Management Message Version. */
#define MME_MMV                 1

/** Default Spidupd block size. */
#define SPIDUPD_BLOCK_SIZE      1024

#include <linux/byteorder/swab.h>

#if __BYTE_ORDER == __LITTLE_ENDIAN
/** The host byte order is the same as MME byte order, so these functions are
 * all just identity. */
#  define mmetohl(x)     (x)
#  define mmetohs(x)     (x)
#  define htommel(x)     (x)
#  define htommes(x)     (x)
#else
#  if __BYTE_ORDER == __BIG_ENDIAN
#    define mmetohl(x)      ___bswap32((x))
#    define mmetohs(x)      ___bswap16((x))
#    define htommel(x)      ___bswap32((x))
#    define htommes(x)      ___bswap16((x))
#  endif
#endif

/** SPIDUPD Messages. */
#define VS_UPDATE_START         0x8000
#define VS_UPDATE_TRANSFER      0x8004
#define VS_UPDATE_END           0x8008

/** Informations about REQ, CNF IND or RSP is held in two LSBs. */
#define VS_UPDATE_START_REQ     (VS_UPDATE_START | 0x0)
#define VS_UPDATE_START_CNF     (VS_UPDATE_START | 0x1)
#define VS_UPDATE_TRANSFER_REQ  (VS_UPDATE_TRANSFER | 0x0)
#define VS_UPDATE_TRANSFER_CNF  (VS_UPDATE_TRANSFER | 0x1)
#define VS_UPDATE_END_REQ       (VS_UPDATE_END | 0x0)
#define VS_UPDATE_END_CNF       (VS_UPDATE_END | 0x1)
#define VS_UPDATE_END_IND       (VS_UPDATE_END | 0x2)

/** SPIDUPD Start Request format. */
struct VsUpdStartReq_t
{
    /** version string of the fw to send */
    unsigned char version[16];
    /** modem arch type; default: 0 (spc300) */
    unsigned char arch;
    /** update type; default: 0 for normal image */
    unsigned char upd_type;
} __attribute__ ((__packed__));
typedef struct VsUpdStartReq_t VsUpdStartReq_t;

/** SPIDUPD Start Confirm format. */
struct VsUpdStartCnf_t
{
    /** 0 - success, 0x1..0x5 - error messages */
    unsigned char start_update;
} __attribute__ ((__packed__));
typedef struct VsUpdStartCnf_t VsUpdStartCnf_t;

/** SPIDUPD Transfer Request format. */
struct VsUpdTransfReq_t
{
    /** block ID of data to be sent */
    unsigned int block_id;
    /** length of data to be sent */
    unsigned int length;
    /** padded data (for min size of eth packet) */
    unsigned char data[MAX_MME_SIZE - 8];
} __attribute__ ((__packed__));
typedef struct VsUpdTransfReq_t VsUpdTransfReq_t;

/** SPIDUPD Transfer Confirm format. */
struct VsUpdTransfCnf_t
{
    /** 0 - success, 0x1 - failure */
    unsigned char ack;
    /** next block ID that server expects */
    unsigned int next_block;
} __attribute__ ((__packed__));
typedef struct VsUpdTransfCnf_t VsUpdTransfCnf_t;

/** SPIDUPD End Request format. */
struct VsUpdEndReq_t
{
    /** 0 - success, 0x1 - failure */
    unsigned char md5_sum[16];
} __attribute__ ((__packed__));
typedef struct VsUpdEndReq_t VsUpdEndReq_t;

/** SPIDUPD End Confirm format. */
struct VsUpdEndCnf_t
{
    /** 0 - success, 0x1 - failure */
    unsigned char result;
} __attribute__ ((__packed__));
typedef struct VsUpdEndCnf_t VsUpdEndCnf_t;

/** SPIDUPD End Indication format. */
struct VsUpdEndInd_t
{
    /** 0 - success, 0x1..0x2 - error messages */
    unsigned char result;
} __attribute__ ((__packed__));
typedef struct VsUpdEndInd_t VsUpdEndInd_t;

/** Failure codes in server response
 * start_cnf */
#define SPIDUPD_OK              0x00
#define SPIDUPD_BAD_VERSION     0x01
#define SPIDUPD_BAD_ARCH        0x02
#define SPIDUPD_BAD_UPD_TYPE    0x03
#define SPIDUPD_MODEM_BUSY      0x04

/** Failure codes in server response
 * transfer_cnf and end_cnf */
#define SPIDUPD_SUCCESS         0x00
#define SPIDUPD_FAILURE         0x01

/** Failure codes in server response
 * end_cnf */
#define SPIDUPD_MD5_ERROR           0x01
#define SPIDUPD_FLASH_WRITE_ERROR   0x02

/** Failure codes in server response
 * end_ind */
#define SPIDUPD_FLASH_WRITE_TOUT    0x02

#endif /* __SPIDUPD_HOST_H__ */