summaryrefslogtreecommitdiff
path: root/cleopatre/tools/spidupd/spidupd_host.h
blob: b2571bde2841ad88bcdfd6416126241f3aa00d4f (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
/*
 * 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
 *
 * Author(s):
 * Drasko DRASKOVIC, drasko.draskovic@spidcom.com
 */

#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];
    /** ieee 802.1q VLAN tag (optional). */
    //unsigned int vlan_tag;
    /** 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 MME_t MME_t;

/** 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 MS_UPDATE_START         0x8000
#define MS_UPDATE_TRANSFER      0x8004
#define MS_UPDATE_END           0x8008

/** Informations about REQ, CNF IND or RSP is held in two LSBs. */
#define MS_UPDATE_START_REQ     (MS_UPDATE_START | 0x0)
#define MS_UPDATE_START_CNF     (MS_UPDATE_START | 0x1)
#define MS_UPDATE_TRANSFER_REQ  (MS_UPDATE_TRANSFER | 0x0)
#define MS_UPDATE_TRANSFER_CNF  (MS_UPDATE_TRANSFER | 0x1)
#define MS_UPDATE_END_REQ       (MS_UPDATE_END | 0x0)
#define MS_UPDATE_END_CNF       (MS_UPDATE_END | 0x1)
#define MS_UPDATE_END_IND       (MS_UPDATE_END | 0x2)

/** SPIDUPD Start Request format. */
struct MsUpdStartReq_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 MsUpdStartreq_t MsUpdStartreq_t;

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

/** SPIDUPD Transfer Request format. */
struct MsUpdTransfReq_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 MsUpdTransfReq_t MsUpdTransfReq_t;

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

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

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

/** SPIDUPD End Indication format. */
struct MsUpdEndInd_t
{
    /** 0 - success, 0x1..0x2 - error messages */
    unsigned char result;
} __attribute__ ((__packed__));
typedef struct MsUpdEndInd_t MsUpdEndInd_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

/** define an address in RAM where we will put update image that is coming
 * from PC client. After download, image will be written to flash */
#define UPD_IMG_RAM_ADDR        ((unsigned char *)0x40100000)

/**
 * Begin SPIDUPD get
 */
extern void
SpidupdStart (void);

/**********************************************************************/

#endif /* __SPIDUPD_HOST_H__ */