lib: added DBData and DBLoader
[barry.git] / src / packet.h
blobaa3483460a2b80f053bcc4475305e2f834bb7b71
1 ///
2 /// \file packet.h
3 /// Low level protocol packet builder class.
4 /// Has knowledge of specific protocol commands in order
5 /// to hide protocol details behind an API.
6 ///
8 /*
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__
27 #include <string>
28 #include <stdint.h>
29 #include "protocol.h"
30 #include "data.h"
32 namespace Barry { class Data; }
34 namespace Barry {
36 // forward declarations
37 class Parser;
38 class Builder;
39 class SocketZero;
40 class Socket;
41 class IConverter;
42 namespace Mode {
43 class Desktop;
44 class JavaLoader;
47 class Packet
49 friend class SocketZero;
50 friend class Socket;
52 protected:
53 Data &m_send, &m_receive;
55 Data& GetSend() { return m_send; }
56 Data& GetReceive() { return m_receive; }
58 public:
59 Packet(Data &send, Data &receive)
60 : m_send(send), m_receive(receive)
62 virtual ~Packet() {}
64 //////////////////////////////////
65 // common response analysis
67 unsigned int Command() const; // throws Error if receive isn't big enough
71 // ZeroPacket class
73 /// Provides an API for building and analyzing socket-0 protocol packets.
74 /// This class relies on 2 external objects: a send and receive Data buffer.
75 ///
76 /// Note that the receive buffer may be modified
77 /// during a packet send, and this class provides API helpers
78 /// to analyze the results.
79 ///
80 class ZeroPacket : public Packet
82 friend class Socket;
84 public:
85 ZeroPacket(Data &send, Data &receive);
86 ~ZeroPacket();
88 //////////////////////////////////
89 // meta access
91 //////////////////////////////////
92 // packet building
94 void GetAttribute(unsigned int object, unsigned int attribute);
95 void Echo(uint64_t us_ticks);
96 void Reset();
99 //////////////////////////////////
100 // response analysis
102 unsigned int ObjectID() const;
103 unsigned int AttributeID() const;
104 uint32_t ChallengeSeed() const;
105 unsigned int RemainingTries() const;
106 unsigned int SocketResponse() const;
107 unsigned char SocketSequence() const;
108 uint8_t CommandResponse() const;
113 // DBPacket class
115 /// Provides an API for building and analyzing raw DB protocol packets.
116 /// This class relies on 3 external objects: a Mode::Desktop object,
117 /// a send Data buffer, and a receive data buffer. Socket and
118 /// connection details are retrieved on a readonly basis from the
119 /// Mode::Desktop object, but both send and receive buffers can be
120 /// modified.
122 /// Note that the receive buffer may be modified
123 /// during a packet send, and this DBPacket class provides API helpers
124 /// to analyze the results.
126 class DBPacket : public Packet
128 friend class Socket;
130 private:
131 Mode::Desktop &m_con;
132 unsigned int m_last_dbop; // last database operation
134 protected:
136 public:
137 DBPacket(Mode::Desktop &con, Data &send, Data &receive);
138 ~DBPacket();
140 //////////////////////////////////
141 // meta access
143 //////////////////////////////////
144 // packet building
146 // commands that correspond to the DB operation
147 // constants in protocol.h
148 void ClearDatabase(unsigned int dbId);
149 void GetDBDB();
150 void GetRecordStateTable(unsigned int dbId);
151 void SetRecordFlags(unsigned int dbId, unsigned int stateTableIndex, uint8_t flag1);
152 void DeleteRecordByIndex(unsigned int dbId, unsigned int stateTableIndex);
153 void GetRecordByIndex(unsigned int dbId, unsigned int stateTableIndex);
154 bool SetRecordByIndex(unsigned int dbId, unsigned int stateTableIndex, Builder &build, const IConverter *ic);
155 void GetRecords(unsigned int dbId);
156 bool SetRecord(unsigned int dbId, Builder &build, const IConverter *ic);
159 //////////////////////////////////
160 // response analysis
162 // DB command response functions
163 unsigned int ReturnCode() const; // throws FIXME if packet doesn't support it
164 unsigned int DBOperation() const; // throws Error on size trouble
166 bool Parse(Parser &parser, const std::string &dbname,
167 const IConverter *ic); // switches based on last m_send command
168 bool ParseMeta(DBData &data);
170 // response parsers
175 // JLPacket class
177 /// Provides an API for building and analyzing raw Javaloader protocol packets.
178 /// This class relies on 3 external objects:
179 /// a command send Data buffer (which can be fairly small), a data
180 /// or argument send Data buffer, and a receive data buffer. Socket and
181 /// connection details are retrieved on a readonly basis from the
182 /// Mode::JavaLoader object, but all buffers can be modified.
184 /// Note that the receive buffer may be modified
185 /// during a packet send, and this JLPacket class provides API helpers
186 /// to analyze the results.
188 class JLPacket : public Packet
190 friend class Socket;
192 private:
193 Data &m_cmd, &m_data;
194 int m_last_set_size;
196 public:
197 JLPacket(Data &cmd, Data &send, Data &receive);
198 ~JLPacket();
200 //////////////////////////////////
201 // meta access
203 bool HasData() const { return m_last_set_size == 2; }
204 Data& GetReceive() { return m_receive; }
206 //////////////////////////////////
207 // packet building
209 // commands that correspond to the operation
210 // constants in protocol.h
212 // returns 1 or 2 depending on whether cmd or cmd+send are available
213 int SimpleCmd(uint8_t cmd, uint8_t unknown = 0, uint16_t size = 0);
214 int SimpleData(const void *data, uint16_t size);
215 int BigEndianData(uint16_t value);
216 int BigEndianData(uint32_t value);
218 int Hello() { return SimpleCmd(SB_COMMAND_JL_HELLO); }
219 int Goodbye() { return SimpleCmd(SB_COMMAND_JL_GOODBYE); }
220 int SetUnknown1();
221 int SetCodFilename(const std::string &filename);
222 int SetCodSize(off_t size);
223 int SetTime(time_t when);
224 int GetScreenshot();
225 int GetData() { return SimpleCmd(SB_COMMAND_JL_SEND_DATA); }
226 int DeviceInfo() { return SimpleCmd(SB_COMMAND_JL_DEVICE_INFO); }
227 int OsMetrics() { return SimpleCmd(SB_COMMAND_JL_OS_METRICS); }
228 int BootromMetrics() { return SimpleCmd(SB_COMMAND_JL_BOOTROM_METRICS); }
229 int GetDirectory() { return SimpleCmd(SB_COMMAND_JL_GET_DIRECTORY); }
230 int GetSubDir(uint16_t id);
231 int GetDirEntry(uint8_t entry_cmd, uint16_t id);
232 int Erase(uint16_t cmd, uint16_t id);
233 int GetEventlog() { return SimpleCmd(SB_COMMAND_JL_GET_LOG); }
234 int GetEventlogEntry(uint16_t entry_num);
235 int ClearEventlog() { return SimpleCmd(SB_COMMAND_JL_CLEAR_LOG); }
236 int SaveModule(uint16_t id);
237 int PutData(const void *data, uint16_t size);
238 int WipeApps() { return SimpleCmd(SB_COMMAND_JL_WIPE_APPS); }
239 int WipeFs() { return SimpleCmd(SB_COMMAND_JL_WIPE_FS); }
240 int LogStackTraces() { return SimpleCmd(SB_COMMAND_JL_LOG_STRACES); }
241 int ResetToFactory() { return SimpleCmd(SB_COMMAND_JL_RESET_FACTORY); }
243 //////////////////////////////////
244 // response analysis
245 unsigned int Size();
250 // JVMPacket class
252 /// Provides an API for building and analyzing raw JavaDebug protocol packets.
253 /// This class relies on 3 external objects:
254 /// a command send Data buffer (which can be fairly small), a data
255 /// or argument send Data buffer, and a receive data buffer. Socket and
256 /// connection details are retrieved on a readonly basis from the
257 /// Mode::JavaDebug object, but all buffers can be modified.
259 /// Note that the receive buffer may be modified
260 /// during a packet send, and this JVMPacket class provides API helpers
261 /// to analyze the results.
263 class JVMPacket : public Packet
265 friend class Socket;
267 private:
268 Data &m_cmd;
270 public:
271 JVMPacket(Data &cmd, Data &receive);
272 ~JVMPacket();
274 //////////////////////////////////
275 // meta access
277 Data& GetReceive() { return m_receive; }
279 //////////////////////////////////
280 // packet building
282 // commands that correspond to the operation
283 // constants in protocol.h
285 // returns 1 or 2 depending on whether cmd or cmd+send are available
286 void SimpleCmd(uint8_t cmd);
287 void ComplexCmd(uint8_t cmd, const void *param, uint16_t size = 0);
289 void Unknown01(); // Command 0x53
290 void Unknown02(); // Command 0x01
291 void Unknown03(); // Command 0x6f
292 void Unknown04(); // Command 0x8a
293 void Unknown05(); // Command 0x90
294 void Unknown06(); // Command 0x44
295 void Unknown07(); // Command 0x45
296 void Unknown08(); // Command 0x54
297 void Unknown09(); // Command 0x33
298 void Unknown10(); // Command 0x46
299 void Unknown11(uint32_t id); // Command 0x0e
300 void Unknown12(uint32_t id); // Command 0x50
301 void Unknown13(uint32_t id); // Command 0x0d
302 void Unknown14(uint32_t id); // Command 0x85
303 void Unknown15(uint32_t id); // Command 0x84
304 void GetModulesList(uint32_t id); // Command 0x8d
305 void GetThreadsList(); // Command 0x08
306 void GetConsoleMessage();
307 void Go(); // Command mal formed :)
308 void Stop(); // Command 0x02
309 void GetStatus(); // Command 0x06
311 //////////////////////////////////
312 // response analysis
313 unsigned int Size();
317 } // namespace Barry
319 #endif