3 /// Low level protocol packet builder class.
4 /// Has knowledge of specific protocol commands in order
5 /// to hide protocol details behind an API.
9 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License in the COPYING file at the
21 root directory of this project for more details.
24 #ifndef __BARRY_PACKET_H__
25 #define __BARRY_PACKET_H__
32 namespace Barry
{ class Data
; }
36 // forward declarations
49 friend class SocketZero
;
56 Data
& GetSend() { return m_send
; }
57 Data
& GetReceive() { return *m_receive
; }
60 Packet(Data
&send
, Data
&receive
)
61 : m_send(send
), m_receive(&receive
)
65 // allow user to override the receive buffer for
66 // optimization purposes, to reduce copies... be
67 // careful with this, since this new Data object
68 // must outlive any usage of it via this Packet class
69 void SetNewReceive(Data
&receive
) { m_receive
= &receive
; }
71 //////////////////////////////////
72 // common response analysis
74 unsigned int Command() const; // throws Error if receive isn't big enough
80 /// Provides an API for building and analyzing socket-0 protocol packets.
81 /// This class relies on 2 external objects: a send and receive Data buffer.
83 /// Note that the receive buffer may be modified
84 /// during a packet send, and this class provides API helpers
85 /// to analyze the results.
87 class ZeroPacket
: public Packet
92 ZeroPacket(Data
&send
, Data
&receive
);
95 //////////////////////////////////
98 //////////////////////////////////
101 void GetAttribute(unsigned int object
, unsigned int attribute
);
102 void Echo(uint64_t us_ticks
);
106 //////////////////////////////////
109 unsigned int ObjectID() const;
110 unsigned int AttributeID() const;
111 uint32_t ChallengeSeed() const;
112 unsigned int RemainingTries() const;
113 unsigned int SocketResponse() const;
114 unsigned char SocketSequence() const;
115 uint8_t CommandResponse() const;
122 /// Provides an API for building and analyzing raw DB protocol packets.
123 /// This class relies on 3 external objects: a Mode::Desktop object,
124 /// a send Data buffer, and a receive data buffer. Socket and
125 /// connection details are retrieved on a readonly basis from the
126 /// Mode::Desktop object, but both send and receive buffers can be
129 /// Note that the receive buffer may be modified
130 /// during a packet send, and this DBPacket class provides API helpers
131 /// to analyze the results.
133 class DBPacket
: public Packet
138 Mode::Desktop
&m_con
;
139 unsigned int m_last_dbop
; // last database operation
144 DBPacket(Mode::Desktop
&con
, Data
&send
, Data
&receive
);
147 //////////////////////////////////
150 //////////////////////////////////
153 // commands that correspond to the DB operation
154 // constants in protocol.h
155 void ClearDatabase(unsigned int dbId
);
157 void GetRecordStateTable(unsigned int dbId
);
158 void SetRecordFlags(unsigned int dbId
, unsigned int stateTableIndex
, uint8_t flag1
);
159 void DeleteRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
);
160 void GetRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
);
161 bool SetRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
, Builder
&build
, const IConverter
*ic
);
162 void GetRecords(unsigned int dbId
);
163 bool SetRecord(unsigned int dbId
, Builder
&build
, const IConverter
*ic
);
166 //////////////////////////////////
169 // DB command response functions
170 unsigned int ReturnCode() const; // throws FIXME if packet doesn't support it
171 unsigned int DBOperation() const; // throws Error on size trouble
173 bool Parse(Parser
&parser
, const std::string
&dbname
,
174 const IConverter
*ic
); // switches based on last m_send command
175 bool ParseMeta(DBData
&data
);
184 /// Provides an API for building and analyzing raw Javaloader protocol packets.
185 /// This class relies on 3 external objects:
186 /// a command send Data buffer (which can be fairly small), a data
187 /// or argument send Data buffer, and a receive data buffer. Socket and
188 /// connection details are retrieved on a readonly basis from the
189 /// Mode::JavaLoader object, but all buffers can be modified.
191 /// Note that the receive buffer may be modified
192 /// during a packet send, and this JLPacket class provides API helpers
193 /// to analyze the results.
195 class JLPacket
: public Packet
200 Data
&m_cmd
, &m_data
;
204 JLPacket(Data
&cmd
, Data
&send
, Data
&receive
);
207 //////////////////////////////////
210 bool HasData() const { return m_last_set_size
== 2; }
211 Data
& GetReceive() { return *m_receive
; }
213 //////////////////////////////////
216 // commands that correspond to the operation
217 // constants in protocol.h
219 // returns 1 or 2 depending on whether cmd or cmd+send are available
220 int SimpleCmd(uint8_t cmd
, uint8_t unknown
= 0, uint16_t size
= 0);
221 int SimpleData(const void *data
, uint16_t size
);
222 int BigEndianData(uint16_t value
);
223 int BigEndianData(uint32_t value
);
225 int Hello() { return SimpleCmd(SB_COMMAND_JL_HELLO
); }
226 int Goodbye() { return SimpleCmd(SB_COMMAND_JL_GOODBYE
); }
228 int SetCodFilename(const std::string
&filename
);
229 int SetCodSize(off_t size
);
230 int SetTime(time_t when
);
232 int GetData() { return SimpleCmd(SB_COMMAND_JL_SEND_DATA
); }
233 int DeviceInfo() { return SimpleCmd(SB_COMMAND_JL_DEVICE_INFO
); }
234 int OsMetrics() { return SimpleCmd(SB_COMMAND_JL_OS_METRICS
); }
235 int BootromMetrics() { return SimpleCmd(SB_COMMAND_JL_BOOTROM_METRICS
); }
236 int GetDirectory() { return SimpleCmd(SB_COMMAND_JL_GET_DIRECTORY
); }
237 int GetSubDir(uint16_t id
);
238 int GetDirEntry(uint8_t entry_cmd
, uint16_t id
);
239 int Erase(uint16_t cmd
, uint16_t id
);
240 int GetEventlog() { return SimpleCmd(SB_COMMAND_JL_GET_LOG
); }
241 int GetEventlogEntry(uint16_t entry_num
);
242 int ClearEventlog() { return SimpleCmd(SB_COMMAND_JL_CLEAR_LOG
); }
243 int SaveModule(uint16_t id
);
244 int PutData(const void *data
, uint16_t size
);
245 int WipeApps() { return SimpleCmd(SB_COMMAND_JL_WIPE_APPS
); }
246 int WipeFs() { return SimpleCmd(SB_COMMAND_JL_WIPE_FS
); }
247 int LogStackTraces() { return SimpleCmd(SB_COMMAND_JL_LOG_STRACES
); }
248 int ResetToFactory() { return SimpleCmd(SB_COMMAND_JL_RESET_FACTORY
); }
250 //////////////////////////////////
259 /// Provides an API for building and analyzing raw JavaDebug protocol packets.
260 /// This class relies on 3 external objects:
261 /// a command send Data buffer (which can be fairly small), a data
262 /// or argument send Data buffer, and a receive data buffer. Socket and
263 /// connection details are retrieved on a readonly basis from the
264 /// Mode::JavaDebug object, but all buffers can be modified.
266 /// Note that the receive buffer may be modified
267 /// during a packet send, and this JVMPacket class provides API helpers
268 /// to analyze the results.
270 class JVMPacket
: public Packet
278 JVMPacket(Data
&cmd
, Data
&receive
);
281 //////////////////////////////////
284 Data
& GetReceive() { return *m_receive
; }
286 //////////////////////////////////
289 // commands that correspond to the operation
290 // constants in protocol.h
292 // returns 1 or 2 depending on whether cmd or cmd+send are available
293 void SimpleCmd(uint8_t cmd
);
294 void ComplexCmd(uint8_t cmd
, const void *param
, uint16_t size
= 0);
296 void Unknown01(); // Command 0x53
297 void Unknown02(); // Command 0x01
298 void Unknown03(); // Command 0x6f
299 void Unknown04(); // Command 0x8a
300 void Unknown05(); // Command 0x90
301 void Unknown06(); // Command 0x44
302 void Unknown07(); // Command 0x45
303 void Unknown08(); // Command 0x54
304 void Unknown09(); // Command 0x33
305 void Unknown10(); // Command 0x46
306 void Unknown11(uint32_t id
); // Command 0x0e
307 void Unknown12(uint32_t id
); // Command 0x50
308 void Unknown13(uint32_t id
); // Command 0x0d
309 void Unknown14(uint32_t id
); // Command 0x85
310 void Unknown15(uint32_t id
); // Command 0x84
311 void GetModulesList(uint32_t id
); // Command 0x8d
312 void GetThreadsList(); // Command 0x08
313 void GetConsoleMessage();
314 void Go(); // Command mal formed :)
315 void Stop(); // Command 0x02
316 void GetStatus(); // Command 0x06
318 //////////////////////////////////