NetBurner 3.5.7
PDF Version
nbupdate.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
16#ifndef __NBUPDATE_H
17#define __NBUPDATE_H
18
19#include <predef.h>
20#include <constants.h>
21#include <basictypes.h>
22#include <PlatformHeader.h>
23
29#define NBUP_ERR_NO_ERR 0
30#define NBUP_ERR_BAD_SOCK -1
31#define NBUP_ERR_TIMEOUT -2
32#define NBUP_ERR_TOO_LARGE -3
33#define NBUP_ERR_WRONG_PLAT -4
34#define NBUP_ERR_BAD_PROG -5
35#define NBUP_ERR_BAD_AUTH -6
38// States...
39// Looking for an S....
40// S getting S record type
41// Parsing Address up to 8 chars)
42// Parsing Data
43// Checking csum....
44
45// S0MOD5441X
46// S315C0040000 40 00 04 00 40 00 05 40 00 05 F6 3C 00 03 AA 5C 1D
47// S315C0040010 1B 41 90 65 A7 0A 18 11 00 41 FF FF 01 4C 6C 80 73
48// S7054000054075
49
50extern const char PlatformName[];
51
52const uint16_t FLAG_DOING_S0 = 1;
53const uint16_t FLAG_DOING_S3 = 2;
54const uint16_t FLAG_DOING_S7 = 4;
55const uint16_t FLAG_SUS_VALID = 8;
56const uint16_t FLAG_SAW_FINALS7 = 16;
57const uint16_t FLAG_SAW_BINARY = 32;
58const uint16_t FLAG_DOING_BINARY = 64;
59const uint16_t FLAG_NEED_AUTH_CHARS = 128;
60const uint16_t FLAG_DONE_S0 = 0x100;
61
62class AppUpdateRecord
63{
64 bool m_bWrittenToFlash;
65 uint8_t m_state;
66 uint8_t m_csum;
67 uint8_t m_cnt;
68 uint16_t m_flags;
69 uint32_t tempv;
70
71 PlatformFlashHeaderStruct bsus;
72 PlatformFlashHeaderStruct sus;
73
74 uint8_t *pRecord;
75#ifdef APP_BUFFER_VERIFY
76 uint8_t *pRecord2;
77#endif
78 uint32_t DataRead;
79 uint32_t BaseAddress;
80 const char *m_Error;
81 int m_ErrorNum;
82
83 public:
84 AppUpdateRecord();
85 ~AppUpdateRecord();
86 // Return true when done
87 bool ParseChars(char *chars, int nChars);
88 void ParseOneChar(char c);
89 void PutValue(uint8_t v);
90 bool resp;
91 bool bUpdateRefused;
92
93 enum
94 {
95 ERR_NO_ERR,
96 ERR_NO_REC,
97 ERR_BAD_RX,
98 ERR_WRITE_FAIL,
99 ERR_ALREADY_WRITTEN,
100 ERR_BAD_ALLOC,
101 ERR_BAD_PLAT,
102 ERR_BAD_AUTH,
103 ERR_BAD_CSUM
104 };
105
106 int DoFlashProgram();
107 bool CsumValid();
108 bool ImageReceived()
109 {
110 if ((m_Error) || (m_ErrorNum) || (!pRecord) || (DataRead < sus.CompleteRecordSize() - sus.SizeWithoutPad()) ||
111 ((m_flags & FLAG_SAW_FINALS7) == 0) || (m_flags & FLAG_NEED_AUTH_CHARS))
112 return false;
113 return true;
114 };
115
116 const char *GetError() { return m_Error; };
117
118 int GetErrorNum() { return m_ErrorNum; }
119
120 void SetBadAuth()
121 {
122 m_ErrorNum = ERR_BAD_AUTH;
123 m_Error = "Bad Authentication";
124 }
125
126 bool bWaitingOnAuth() { return (((m_flags & FLAG_NEED_AUTH_CHARS) != 0) || (m_ErrorNum == ERR_BAD_AUTH)); }
127
128 uint32_t GetbaseAddress() { return BaseAddress; };
129
130 uint32_t GetLength() { return sus.CompleteRecordSize() - sus.SizeWithoutPad(); };
131
132 uint32_t GetFullLength() { return bsus.CompleteRecordSize(); };
133
134 const uint8_t *GetData() { return pRecord; };
135
136 bool IsBinary() { return ((m_flags & FLAG_DOING_BINARY) != 0); }
137
138 int32_t GetRemainingLen() { return (int32_t)bsus.CompleteRecordSize() - DataRead; }
139};
140
141enum AppAuthResult
142{
143 eOKToProgram,
144 eBadSignature,
145 eMoreData
146};
147
148// Helper functiosn for signed apps.
149typedef AppAuthResult (*AppAuthenticateFunc)(AppUpdateRecord *ar, uint8_t *chars, int n);
150extern AppAuthenticateFunc pAppAuthFunc;
151
160void RegisterAppSigningPublicKey(const char *pKey);
161
172int ProgramApplication(uint32_t where, uint8_t *pAppImage);
173
185int UpdateFromStream(int fd, AppUpdateRecord *&pu, uint32_t timeout);
186
187#endif /* ----- #ifndef __NBUPDATE_H ----- */
188
int ProgramApplication(uint32_t where, uint8_t *pAppImage)
Program an appliction image into Flash memory.
int UpdateFromStream(int fd, AppUpdateRecord *&pu, uint32_t timeout)
Program/update an appliction image from a data stream.
void RegisterAppSigningPublicKey(const char *pKey)
Enable APP Signing by registering a RSA PEM or DER format public key.