doc: updated bio man page with new cstore output mode
[barry.git] / src / protostructs.h
blob3e2cd96ec113426bad3becf34a238c65aa77587e
1 ///
2 /// \file protostructs.h
3 /// USB Blackberry bulk protocol API. This is split out from
4 /// protocol.h so that low level, packed structs can be
5 /// compiled separately from the application. This prevents
6 /// aliasing problems in the application, or using
7 /// -fno-strict-aliasing, which the library only needs.
8 ///
9 /// Do not include this in any Barry library header.
10 /// This may only be included from .cc files, in order
11 /// to hide aliasing concernes from the application.
12 ///
15 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 See the GNU General Public License in the COPYING file at the
27 root directory of this project for more details.
30 #ifndef __BARRY_PROTOSTRUCTS_H__
31 #define __BARRY_PROTOSTRUCTS_H__
33 #include <stdint.h>
34 #include <sys/types.h>
36 // forward declarations
37 namespace Barry { class Data; }
39 namespace Barry { namespace Protocol {
41 ///////////////////////////////////////////////////////////////////////////////
42 union SizePacket
44 uint16_t size;
45 char buffer[4];
46 } __attribute__ ((packed));
49 ///////////////////////////////////////////////////////////////////////////////
50 // Record sub-field structs
52 struct GroupLink // used for Contacts records
54 uint32_t uniqueId;
55 uint16_t unknown;
56 } __attribute__ ((packed));
58 struct MessageAddress // used for Message records
60 uint8_t unknown[8];
61 uint8_t addr[1]; // 2 null terminated strings: first
62 // contains full name, second contains
63 // the email address
64 } __attribute__ ((packed));
67 ///////////////////////////////////////////////////////////////////////////////
68 // SMS Message field and record structures
70 struct SMSMetaData
72 uint8_t recv; // if received, this is set to 1; otherwise 0
73 uint8_t flags;
74 #define SMS_FLG_NEW_CONVERSATION 0x20
75 #define SMS_FLG_SAVED 0x10
76 #define SMS_FLG_DELETED 0x08
77 #define SMS_FLG_OPENED 0x01
79 uint8_t new_flag;
80 uint16_t zero; // constantly 0
81 uint32_t status;
82 #define SMS_STA_RECEIVED 0x000007ff
83 #define SMS_STA_DRAFT 0x7fffffff
85 uint32_t error_id;
86 uint64_t timestamp;
87 uint64_t service_center_timestamp;
88 uint8_t dcs;
89 #define SMS_DCS_7BIT 0x00
90 #define SMS_DCS_8BIT 0x01
91 #define SMS_DCS_UCS2 0x02
93 } __attribute__ ((packed));
94 #define SMS_METADATA_SIZE (sizeof(::Barry::Protocol::SMSMetaData))
98 ///////////////////////////////////////////////////////////////////////////////
99 // Record Field Formats
101 struct CommonField
103 uint16_t size; // including null terminator
104 uint8_t type;
106 union CommonFieldData
109 GroupLink link;
110 MessageAddress addr;
111 SMSMetaData sms_metadata;
112 uint64_t timestamp;
113 uint64_t uint64;
114 uint32_t uint32;
115 int32_t min1900;
116 uint16_t code;
117 uint8_t raw[1];
118 int16_t int16;
120 } __attribute__ ((packed)) u;
122 } __attribute__ ((packed));
123 #define COMMON_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::CommonField) - sizeof(::Barry::Protocol::CommonField::CommonFieldData))
124 #define COMMON_FIELD_MIN1900_SIZE (sizeof(int32_t))
126 struct CommandTableField
128 uint8_t size; // no null terminator
129 uint8_t code;
130 uint8_t name[1];
131 } __attribute__ ((packed));
132 #define COMMAND_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::CommandTableField) - 1)
134 struct OldDBDBField
136 uint16_t dbNumber;
137 uint8_t unknown1;
138 uint32_t dbSize; // assumed from Cassis docs...
139 // always 0 in USB
140 uint16_t dbRecordCount;
141 uint16_t unknown2;
142 uint16_t nameSize; // includes null terminator
143 uint8_t name[1];
144 } __attribute__ ((packed));
145 #define OLD_DBDB_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::OldDBDBField) - 1)
147 struct DBDBField
149 uint16_t dbNumber;
150 uint8_t unknown1;
151 uint32_t dbSize; // assumed from Cassis docs...
152 // always 0 in USB
153 uint32_t dbRecordCount;
154 uint16_t unknown2;
155 uint16_t nameSize; // includes null terminator
156 uint8_t unknown3;
157 uint8_t name[1]; // followed by 2 zeros!
158 uint16_t unknown; // this comes after the
159 // null terminated name, but
160 // is here for size calcs
161 } __attribute__ ((packed));
162 #define DBDB_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::DBDBField) - 1)
164 struct RecordStateTableField
166 uint8_t rectype; // it is unknown exactly what
167 // this field does, but it
168 // shows up here and in the
169 // tagged record header, and
170 // for some of the records
171 // they must match when writing
172 uint16_t index;
173 uint32_t uniqueId; // matches the uniqueId of say,
174 // address book records
175 uint8_t flags; // bit 0x01 is the dirty flag
176 // don't know if any other bits
177 // are used
178 #define BARRY_RSTF_DIRTY 0x01
179 uint8_t unknown2[4];
180 } __attribute__ ((packed));
182 struct CalendarRecurrenceDataField // as documented in the Cassis project spec
184 uint8_t type;
185 #define CRDF_TYPE_DAY 0x01
186 #define CRDF_TYPE_MONTH_BY_DATE 0x03
187 #define CRDF_TYPE_MONTH_BY_DAY 0x04
188 #define CRDF_TYPE_YEAR_BY_DATE 0x05
189 #define CRDF_TYPE_YEAR_BY_DAY 0x06
190 #define CRDF_TYPE_WEEK 0x0c
192 uint8_t unknown; // always 0x01
193 uint16_t interval;
194 uint32_t startTime;
195 uint32_t endTime; // 0xFFFFFFFF for never
197 union Additional
199 // Note: blank fields should be set to 0
201 struct Day
203 uint8_t day[6]; // always zeros!
204 } __attribute__ ((packed)) day;
206 struct MonthByDate
208 uint8_t monthDay; // day of month to recur on
209 // (1-31)
210 uint8_t blank[5];
211 } __attribute__ ((packed)) month_by_date;
213 struct MonthByDay
215 uint8_t weekDay; // day of week to recur on (0-6)
216 uint8_t week; // week of month to recur on
217 // (1 to 5, first week, second
218 // week, etc)
219 uint8_t blank[4];
220 } __attribute__ ((packed)) month_by_day;
222 struct YearByDate
224 uint8_t monthDay; // day of month to recur on
225 // (1-31)
226 uint8_t blank;
227 uint8_t month; // month to recur on (1-12)
228 uint8_t blank_[3];
229 } __attribute__ ((packed)) year_by_date;
231 struct YearByDay
233 uint8_t weekDay; // day of week to recur on (0-6)
234 uint8_t week; // week of month (1 to 5)
235 uint8_t month; // (1-12)
236 uint8_t blank[3];
237 } __attribute__ ((packed)) year_by_day;
239 struct Week
241 uint8_t days; // bitmask
242 #define CRDF_WD_SUN 0x01
243 #define CRDF_WD_MON 0x02
244 #define CRDF_WD_TUE 0x04
245 #define CRDF_WD_WED 0x08
246 #define CRDF_WD_THU 0x10
247 #define CRDF_WD_FRI 0x20
248 #define CRDF_WD_SAT 0x40
250 uint8_t blank[5];
251 } __attribute__ ((packed)) week;
253 } __attribute__ ((packed)) u;
255 } __attribute__ ((packed));
256 #define CALENDAR_RECURRENCE_DATA_FIELD_SIZE sizeof(::Barry::Protocol::CalendarRecurrenceDataField)
259 // Calendar record: field constants
262 #define CR_FREEBUSY_FREE 0
263 #define CR_FREEBUSY_TENTATIVE 1
264 #define CR_FREEBUSY_BUSY 2
265 #define CR_FREEBUSY_OUT_OF_OFFICE 3
266 #define CR_FREEBUSY_RANGE_LOW 0
267 #define CR_FREEBUSY_RANGE_HIGH 3
269 #define CR_CLASS_PUBLIC 0
270 #define CR_CLASS_CONFIDENTIAL 1
271 #define CR_CLASS_PRIVATE 2
272 #define CR_CLASS_RANGE_LOW 0
273 #define CR_CLASS_RANGE_HIGH 2
277 // Task record: field constants
280 #define TR_ALARM_DATE 1
281 #define TR_ALARM_RELATIVE 2
282 #define TR_ALARM_RANGE_LOW 1
283 #define TR_ALARM_RANGE_HIGH 2
285 #define TR_PRIORITY_HIGH 0
286 #define TR_PRIORITY_NORMAL 1
287 #define TR_PRIORITY_LOW 2
288 #define TR_PRIORITY_RANGE_LOW 0
289 #define TR_PRIORITY_RANGE_HIGH 2
291 #define TR_STATUS_NOT_STARTED 0
292 #define TR_STATUS_IN_PROGRESS 1
293 #define TR_STATUS_COMPLETED 2
294 #define TR_STATUS_WAITING 3
295 #define TR_STATUS_DEFERRED 4
296 #define TR_STATUS_RANGE_LOW 0
297 #define TR_STATUS_RANGE_HIGH 4
300 // Phone Call Logs record: field constants
303 #define CLL_DIRECTION_RECEIVER 0
304 #define CLL_DIRECTION_EMITTER 1
305 #define CLL_DIRECTION_FAILED 2
306 #define CLL_DIRECTION_MISSING 3
307 #define CLL_DIRECTION_RANGE_LOW 0
308 #define CLL_DIRECTION_RANGE_HIGH 3
310 #define CLL_PHONETYPE_UNDEFINED 0
311 #define CLL_PHONETYPE_OFFICE 1
312 #define CLL_PHONETYPE_HOME 2
313 #define CLL_PHONETYPE_MOBILE 3
314 #define CLL_PHONETYPE_RANGE_LOW 0
315 #define CLL_PHONETYPE_RANGE_HIGH 3
318 // Browser Bookmarks record: field constants
321 #define BMK_BROWSER_AUTO 0
322 #define BMK_BROWSER_BLACKBERRY 1
323 #define BMK_BROWSER_FIREFOX 2
324 #define BMK_BROWSER_INTERNET_EXPLORER 3
326 #define BMK_DISPLAY_AUTO 0
327 #define BMK_DISPLAY_COLOMN 1
328 #define BMK_DISPLAY_PAGE 2
330 #define BMK_JAVASCRIPT_AUTO 0
331 #define BMK_JAVASCRIPT_ENABLED 1
332 #define BMK_JAVASCRIPT_DISABLED 2
334 struct StringField
336 uint16_t be_size; // may or may not have a null term.
337 // big-endian
338 uint8_t data[1];
339 } __attribute__ ((packed));
340 #define STRING_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::StringField) - 1)
342 struct BookmarkId
344 uint32_t bookmark_id;
345 uint8_t index;
346 } __attribute__ ((packed));
347 #define BOOKMARK_ID_SIZE (sizeof(::Barry::Protocol::BookmarkId))
349 struct VarStringField
351 uint8_t present;
352 uint16_t be_size; // big-endian
353 uint8_t data[1];
354 } __attribute__ ((packed));
355 #define VARSTRING_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::VarStringField) - 1)
357 struct BookmarkFolders
359 uint32_t id1; // these two fields contain
360 uint32_t id2; // b9 fc f8 f6 c2 e3 a4 d5
361 // whenever there is a record in
362 // the Blackberry Bookmarks folder,
363 // even across multiple devices!
364 // this was true for the 9550 and
365 // the oooold 7750, and the 8700
366 uint8_t unknown; // may be a section code? seems to
367 // always be 0x08
368 uint8_t flag; // unknown flag
369 } __attribute__ ((packed));
370 #define BOOKMARK_FOLDERS_HEADER_SIZE (sizeof(::Barry::Protocol::BookmarkFolders))
374 // Folder record: field constants
377 #define FR_TYPE_SUBTREE 0x00
378 #define FR_TYPE_DELETED 0x01
379 #define FR_TYPE_INBOX 0x02
380 #define FR_TYPE_OUTBOX 0x03
381 #define FR_TYPE_SENT 0x04
382 #define FR_TYPE_OTHER 0x05
383 #define FR_TYPE_DRAFT 0x0a
385 #define FR_STATUS_ORPHAN 0x50
386 #define FR_STATUS_UNFILED 0x51
387 #define FR_STATUS_FILED 0x52
390 ///////////////////////////////////////////////////////////////////////////////
391 // Packed field structures - odd format used with Service Book records
393 struct PackedField_02
395 uint8_t code;
396 uint8_t size;
397 uint8_t type;
398 uint8_t raw[1];
399 } __attribute__ ((packed));
400 #define PACKED_FIELD_02_HEADER_SIZE (sizeof(::Barry::Protocol::PackedField_02) - 1)
402 struct PackedField_10
404 uint8_t type;
405 uint8_t size;
406 uint8_t raw[1];
407 } __attribute__ ((packed));
408 #define PACKED_FIELD_10_HEADER_SIZE (sizeof(::Barry::Protocol::PackedField_10) - 1)
413 ///////////////////////////////////////////////////////////////////////////////
414 // Service Book field and record structures
416 struct ServiceBookConfigField
418 uint8_t format;
419 uint8_t fields[1];
420 } __attribute__ ((packed));
421 #define SERVICE_BOOK_CONFIG_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::ServiceBookConfigField) - 1)
424 ///////////////////////////////////////////////////////////////////////////////
425 // DB Command Parameter structures
427 struct DBC_Record
429 uint16_t recordIndex; // index comes from RecordStateTable
430 uint8_t data[1];
431 } __attribute__ ((packed));
432 #define DBC_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBC_Record) - 1)
434 struct DBC_RecordFlags
436 uint8_t unknown;
437 uint16_t index;
438 uint8_t unknown2[5];
439 } __attribute__ ((packed));
440 #define DBC_RECORD_FLAGS_SIZE (sizeof(::Barry::Protocol::DBC_RecordFlags))
442 struct DBC_TaggedUpload
444 uint8_t rectype; // it is unknown exactly what
445 // this field does, but it
446 // shows up here and in the
447 // RecordStateTable, and
448 // for some of the records
449 // they must match when writing
450 uint32_t uniqueId;
451 uint8_t unknown2;
452 uint8_t data[1];
453 } __attribute__ ((packed));
454 #define DBC_TAGGED_UPLOAD_HEADER_SIZE (sizeof(::Barry::Protocol::DBC_TaggedUpload) - 1)
456 struct DBC_IndexedUpload
458 uint8_t unknown; // observed: 00 or 05
459 uint16_t index;
460 uint8_t data[1];
461 } __attribute__ ((packed));
462 #define DBC_INDEXED_UPLOAD_HEADER_SIZE (sizeof(::Barry::Protocol::DBC_IndexedUpload) - 1)
464 struct PasswordChallenge
466 uint8_t remaining_tries; // number of password attempts
467 // the device will accept before
468 // committing suicide...
469 // starts at 10 and counts down
470 // on each bad password
471 uint8_t unknown; // observed as 0... probably just
472 // the top byte of a uint16
473 // remaining_tries, but I don't
474 // want to take that chance
475 uint16_t param; // seems to be a secondary command
476 // of some kind, observed as 0x14
477 // or 0x04, but purpose unknown
478 // possibly a send/receive flag
479 // bit (0x10/0x00)
480 union Hash
482 uint32_t seed;
483 uint8_t hash[20];
484 } __attribute__ ((packed)) u;
486 } __attribute__ ((packed));
487 #define PASSWORD_CHALLENGE_HEADER_SIZE (sizeof(::Barry::Protocol::PasswordChallenge) - sizeof(::Barry::Protocol::PasswordChallenge::Hash))
488 #define PASSWORD_CHALLENGE_SEED_SIZE (PASSWORD_CHALLENGE_HEADER_SIZE + sizeof(uint32_t))
489 #define PASSWORD_CHALLENGE_SIZE (sizeof(::Barry::Protocol::PasswordChallenge))
491 struct AttributeFetch
493 uint16_t object;
494 uint16_t attribute;
495 uint8_t raw[1]; // used only in response
496 } __attribute__ ((packed));
497 #define ATTRIBUTE_FETCH_COMMAND_SIZE (sizeof(::Barry::Protocol::AttributeFetch) - 1)
499 struct ModeSelect
501 uint8_t name[16];
502 struct ResponseBlock
504 uint8_t unknown[20];
505 } __attribute__ ((packed)) response;
506 } __attribute__ ((packed));
508 struct Echo
510 uint64_t ticks; // number of microseconds since
511 // host system startup
512 } __attribute__ ((packed));
513 #define ECHO_COMMAND_SIZE (sizeof(::Barry::Protocol::Echo))
516 ///////////////////////////////////////////////////////////////////////////////
517 // Protocol command structures
519 struct SocketCommand
521 uint16_t socket;
522 uint8_t sequence; // incremented on each socket 0
523 // communication, replies return
524 // the same number from command
526 union PacketData
529 PasswordChallenge password;
530 AttributeFetch fetch;
531 ModeSelect mode;
532 uint8_t raw[1];
533 Echo echo;
535 } __attribute__ ((packed)) u;
536 } __attribute__ ((packed));
537 #define SOCKET_COMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::SocketCommand) - sizeof(::Barry::Protocol::SocketCommand::PacketData))
539 struct SequenceCommand
541 uint8_t unknown1;
542 uint8_t unknown2;
543 uint8_t unknown3;
544 uint32_t sequenceId;
545 } __attribute__ ((packed));
547 struct DBCommand
549 uint8_t operation; // see below
550 uint16_t databaseId; // value from the Database Database
552 union Parameters
555 DBC_Record record;
556 DBC_RecordFlags flags;
557 DBC_TaggedUpload tag_upload;
558 DBC_IndexedUpload index_upload;
559 uint8_t raw[1];
561 } __attribute__ ((packed)) u;
562 } __attribute__ ((packed));
563 #define DB_COMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::DBCommand) - sizeof(::Barry::Protocol::DBCommand::Parameters))
567 ///////////////////////////////////////////////////////////////////////////////
568 // Protocol response parameter structures
570 struct DBR_OldDBDBRecord
572 uint16_t count; // number of fields in record
573 OldDBDBField field[1];
574 } __attribute__ ((packed));
575 #define OLD_DBDB_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBR_OldDBDBRecord) - sizeof(::Barry::Protocol::OldDBDBField))
577 struct DBR_DBDBRecord
579 uint16_t count;
580 uint8_t unknown[3];
581 DBDBField field[1];
582 } __attribute__ ((packed));
583 #define DBDB_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBR_DBDBRecord) - sizeof(::Barry::Protocol::DBDBField))
585 // Records with a uniqueId. This covers the following records:
587 // Old Contact records
588 // Old Service Book records
589 // Old Calendar records
591 struct DBR_OldTaggedRecord
593 uint8_t rectype;
594 uint16_t index;
595 uint32_t uniqueId;
596 uint8_t unknown2;
598 union TaggedData
600 CommonField field[1];
601 } __attribute__ ((packed)) u;
602 } __attribute__ ((packed));
603 #define DBR_OLD_TAGGED_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBR_OldTaggedRecord) - sizeof(::Barry::Protocol::DBR_OldTaggedRecord::TaggedData))
605 struct MessageRecord
607 uint8_t field1; // always 'j'
608 uint32_t field2; // always 0x00000000
609 uint32_t flags; // flags
610 uint32_t field4; // normal email and pin recv this is 0x7ff
611 // changes on sent and reply to 0x01ffffff
612 // and 0x003fffff on pin send
613 uint32_t field5; // always 0x00000000
614 uint32_t field6; // always 0x00000000
615 uint32_t field7; // always 0x00000000
616 uint32_t field8; // always 0x00000000
617 uint16_t field9; // always 0x0000
619 uint16_t dateReceived; // the first two of these time fields are always the same
620 uint16_t timeReceived; //
621 uint16_t dateDuplicate; // On mail sent from the BB all three fields are identical
622 uint16_t timeDuplicate; // (time sent)
623 uint16_t dateSent;
624 uint16_t timeSent;
626 uint16_t priority; // priority field
627 uint32_t field14; // always 0x00000000
628 uint32_t field15; // always 0x00000000
629 uint16_t field16; // always 0x0000
630 uint32_t field13; // PIN reply 0x00000000 other time 0xffffffff or 0xfffffffe
631 uint16_t messageSize; // Message size, 0x0000 if Reply or Saved, 0xffff if below ????
632 uint32_t field18; // 0x0's and 0xF'x
633 uint32_t field19; // 0x0's and 0xF's
634 uint16_t field20; // always 0x0000
635 uint16_t field21; // 0x01 unless PIN reply then 0x00
636 uint32_t inReplyTo; // reply to message?
637 uint32_t field22; // always 0x00000000
638 uint16_t field23; // FIXME
640 uint32_t folderOne; // these are the 'folders' the message is in
641 uint32_t folderTwo; //
643 uint16_t replyMessageFlags; // 0xfffe on recvd messages
644 // 0x001b on reply
645 // 0x0015 on send
646 // 0x3 pin send
647 // 0x2 on pin recv
648 uint16_t field27; // set to 0x00000004 on PIN reply, 0x00000005 otherwise
649 uint32_t headerUID; // yet another copy of the UID (RecId)
651 uint32_t field29; // always 0x00000000
652 uint16_t field30; // always 0x0002
653 uint16_t field31; // always 0x00000000
654 uint16_t field32; // always 0x0004
655 uint16_t field34; // always 0x0000
656 uint8_t field33; // always 'd'
657 uint32_t timeBlock; // FIXME
658 CommonField field[1];
659 } __attribute__ ((packed));
660 #define MESSAGE_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::MessageRecord) - sizeof(::Barry::Protocol::CommonField))
664 ///////////////////////////////////////////////////////////////////////////////
665 // Protocol response structures
667 struct DBResponse
669 uint8_t operation;
671 union Parameters
674 DBR_OldTaggedRecord tagged;
675 DBR_OldDBDBRecord old_dbdb;
676 DBR_DBDBRecord dbdb;
678 } __attribute__ ((packed)) u;
680 } __attribute__ ((packed));
681 #define DB_RESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::DBResponse) - sizeof(::Barry::Protocol::DBResponse::Parameters))
685 ///////////////////////////////////////////////////////////////////////////////
686 // Database access command structure
688 // even fragmented packets have a tableCmd
689 struct DBAccess
691 uint8_t tableCmd;
693 union DBData
695 DBCommand command;
696 DBResponse response;
697 CommandTableField table[1];
698 uint8_t return_code;
699 uint8_t fragment[1];
701 } __attribute__ ((packed)) u;
702 } __attribute__ ((packed));
703 #define SB_DBACCESS_HEADER_SIZE (sizeof(::Barry::Protocol::DBAccess) - sizeof(::Barry::Protocol::DBAccess::DBData))
704 #define SB_DBACCESS_RETURN_CODE_SIZE (1)
708 ///////////////////////////////////////////////////////////////////////////////
709 // Javaloader protocol structure
711 struct JLDirEntry
713 uint16_t unknown;
714 uint32_t timestamp;
715 uint16_t filename_size;
716 uint8_t filename[1];
717 // the rest of the packet is variable length
718 // another string for version, then:
719 // uint32_t cod_size;
721 } __attribute__ ((packed));
722 #define SB_JLDIRENTRY_HEADER_SIZE (sizeof(::Barry::Protocol::JLDirEntry) - 1)
724 struct JLCommand
726 uint8_t command;
727 uint8_t unknown; // nearly always 0, might be top half of command
728 uint16_t size;
729 } __attribute__ ((packed));
730 #define SB_JLCOMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::JLCommand))
732 struct JLResponse
734 uint8_t command;
735 uint8_t unknown;
736 uint16_t expect;
737 } __attribute__ ((packed));
738 #define SB_JLRESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::JLResponse))
740 struct JLScreenInfo
742 uint16_t unknown1;
743 uint16_t unknown2;
744 uint16_t unknown3;
745 uint16_t width;
746 uint16_t height;
747 uint16_t unknown4;
748 uint16_t unknown5;
749 uint16_t unknown6;
750 } __attribute__ ((packed));
751 #define SB_JLSCREENINFO_SIZE (sizeof(::Barry::Protocol::JLScreenInfo))
753 struct JLEventlogEntry
755 uint16_t size;
756 // remainder of packet is variable
757 // it contains the log data as an ASCII (UTF-8?) string
758 } __attribute__ ((packed));
759 #define SB_JLEVENTLOG_ENTRY_HEADER_SIZE (sizeof(::Barry::Protocol::JLEventlogEntry))
761 struct JLDeviceInfo
763 uint32_t hardware_id;
764 uint32_t pin;
765 uint32_t os_version;
766 uint32_t vm_version;
767 uint32_t radio_id;
768 uint32_t vendor_id;
769 uint32_t active_wafs;
770 // older devices (such as 7130) don't this extra data in the
771 // device info packet and will therefore fail the size check
772 //uint8_t raw[4];
773 } __attribute__ ((packed));
774 #define SB_JLDEVICEINFO_SIZE (sizeof(::Barry::Protocol::JLDeviceInfo))
776 struct JLPacket
778 uint16_t socket;
779 uint16_t size; // total size of data packet
781 union PacketData
783 JLCommand command;
784 JLResponse response;
785 JLScreenInfo screeninfo;
786 JLEventlogEntry logentry;
787 JLDeviceInfo devinfo;
788 uint8_t raw[1];
789 char filename[1];
790 uint32_t cod_size;
791 uint32_t timestamp;
792 uint16_t id;
793 } __attribute__ ((packed)) u;
795 } __attribute__ ((packed));
796 #define SB_JLPACKET_HEADER_SIZE (sizeof(::Barry::Protocol::JLPacket) - sizeof(::Barry::Protocol::JLPacket::PacketData))
799 ///////////////////////////////////////////////////////////////////////////////
800 // JavaDebug protocol structures
802 namespace JDWP {
804 // Packet command
805 //----------------
807 struct PacketEventRequestSet {
808 uint8_t eventKind;
809 uint8_t suspendPolicy;
810 uint32_t modifiers;
811 } __attribute__ ((packed));
814 struct PacketEventRequest {
815 union PacketEventRequestData {
816 PacketEventRequestSet set;
817 } __attribute__ ((packed)) u;
818 } __attribute__ ((packed));
821 struct PacketCommand {
822 uint8_t commandset;
823 uint8_t command;
825 union PacketCommandData {
826 PacketEventRequest eventRequest;
827 } __attribute__ ((packed)) u;
828 } __attribute__ ((packed));
829 #define JDWP_COMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::JDWP::PacketCommand))
832 // Packet response
833 //-----------------
835 struct PacketVirtualMachineIDSizes {
836 uint32_t fieldIDSize;
837 uint32_t methodIDSize;
838 uint32_t objectIDSize;
839 uint32_t referenceTypeIDSize;
840 uint32_t frameIDSize;
841 } __attribute__ ((packed));
843 #define JDWP_PACKETVIRTUALMACHINEIDSIZES_DATA_SIZE sizeof(::Barry::Protocol::JDWP::PacketVirtualMachineIDSizes)
846 struct PacketVirtualMachine {
847 union PacketVirtualMachineData {
848 PacketVirtualMachineIDSizes IDSizes;
849 } __attribute__ ((packed)) u;
850 } __attribute__ ((packed));
853 struct PacketResponse {
854 uint16_t errorcode;
856 union PacketResponseData {
857 PacketVirtualMachine virtualMachine;
858 uint32_t value;
859 uint8_t raw[1];
860 } __attribute__ ((packed)) u;
861 } __attribute__ ((packed));
862 #define JDWP_RESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::JDWP::PacketResponse) - sizeof(::Barry::Protocol::JDWP::PacketResponse::PacketResponseData))
865 // Generic packet
866 //----------------
868 struct Packet {
869 uint32_t length;
870 uint32_t id;
871 uint8_t flags;
873 union PacketType {
874 PacketCommand command;
875 PacketResponse response;
876 } __attribute__ ((packed)) u;
877 } __attribute__ ((packed));
878 #define JDWP_PACKET_HEADER_SIZE (sizeof(::Barry::Protocol::JDWP::Packet) - sizeof(::Barry::Protocol::JDWP::Packet::PacketType))
881 #define MAKE_JDWPPACKET(var, data) const ::Barry::Protocol::JDWP::Packet *var = (const ::Barry::Protocol::JDWP::Packet *) (data).GetData()
882 #define MAKE_JDWPPACKETPTR_BUF(var, ptr) ::Barry::Protocol::JDWP::Packet *var = (::Barry::Protocol::JDWP::Packet *)ptr
885 } // namespace JDWP
887 struct JDWField {
888 uint32_t size;
890 union JDWFieldData {
891 uint8_t raw[1];
892 } __attribute__ ((packed)) u;
893 } __attribute__ ((packed));
894 #define JDWP_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::JDWField) - sizeof(::Barry::Protocol::JDWField::JDWFieldData))
896 struct JVMCommand
898 uint16_t size;
899 uint8_t command;
900 uint8_t raw[1];
901 } __attribute__ ((packed));
902 #define SB_JVMCOMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::JVMCommand))
904 struct JVMResponse
906 uint8_t command;
907 uint8_t unknown;
908 uint16_t expect;
909 } __attribute__ ((packed));
910 #define SB_JVMRESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::JVMResponse))
912 struct JVMModulesList
914 uint32_t nbr;
915 // remainder of packet is variable
916 // it contains the modules list
917 } __attribute__ ((packed));
918 #define SB_JVMMODULES_LIST_HEADER_SIZE (sizeof(::Barry::Protocol::JVMModulesList))
920 struct JVMModulesEntry
922 uint32_t id;
923 uint32_t uniqueId;
924 uint16_t sizename;
925 // remainder of packet is variable
926 // it contains the module name
927 } __attribute__ ((packed));
928 #define SB_JVMMODULES_ENTRY_HEADER_SIZE (sizeof(::Barry::Protocol::JVMModulesEntry))
930 struct JVMThreadsList
932 uint32_t nbr;
933 // remainder of packet is variable
934 // it contains the threads list
935 } __attribute__ ((packed));
936 #define SB_JVMTHREADS_LIST_HEADER_SIZE (sizeof(::Barry::Protocol::JVMThreadsList))
938 struct JVMUnknown01
940 uint8_t byte;
941 uint32_t address;
942 } __attribute__ ((packed));
943 #define SB_JVMUNKNOWN01_HEADER_SIZE (sizeof(::Barry::Protocol::JVMUnknown01))
945 struct JVMUnknown02
947 uint32_t address1;
948 uint32_t address2;
949 } __attribute__ ((packed));
950 #define SB_JVMUNKNOWN02_HEADER_SIZE (sizeof(::Barry::Protocol::JVMUnknown02))
952 struct JVMPacket
954 uint16_t socket;
955 uint16_t size; // total size of data packet
957 union PacketData
959 JVMCommand command;
960 JVMResponse response;
961 JVMModulesList moduleslist;
962 JVMThreadsList threadslist;
963 JVMUnknown01 unknown01;
964 JVMUnknown02 unknown02;
965 uint32_t address;
966 uint16_t expect;
967 uint16_t msglength;
968 uint16_t value;
969 uint8_t status;
970 uint8_t raw[1];
971 } __attribute__ ((packed)) u;
973 } __attribute__ ((packed));
974 #define SB_JVMPACKET_HEADER_SIZE (sizeof(::Barry::Protocol::JVMPacket) - sizeof(::Barry::Protocol::JVMPacket::PacketData))
977 /////////////////////////////////////////////////////////////////////////////
978 // Raw channel packet structure
979 struct ChannelPacket
981 uint16_t socket; // socket ID... 0 exists by default
982 uint16_t size; // total size of data packet
984 union PacketData
986 uint8_t data[1];
987 } __attribute__ ((packed)) u;
988 } __attribute__ ((packed));
989 #define SB_CHANNELPACKET_HEADER_SIZE (sizeof(::Barry::Protocol::ChannelPacket) - sizeof(::Barry::Protocol::ChannelPacket::PacketData))
991 #define SB_CHANNELPACKET_MAX_DATA_SIZE 0x3FFC
993 ///////////////////////////////////////////////////////////////////////////////
994 // Main packet struct
996 struct Packet
998 uint16_t socket; // socket ID... 0 exists by default
999 uint16_t size; // total size of data packet
1000 uint8_t command;
1002 union PacketData
1005 SocketCommand socket;
1006 SequenceCommand sequence;
1007 DBAccess db;
1008 uint8_t raw[1];
1010 } __attribute__ ((packed)) u;
1011 } __attribute__ ((packed));
1012 #define SB_PACKET_SOCKET_SIZE (sizeof(uint16_t)) // size needed to read the socket in a packet
1013 #define SB_PACKET_HEADER_SIZE (sizeof(::Barry::Protocol::Packet) - sizeof(::Barry::Protocol::Packet::PacketData))
1015 // WARNING : For JavaLoader we have some packet with 5 size !
1016 #define MIN_PACKET_SIZE 5
1017 #define MIN_PACKET_DATA_SIZE 4
1020 // maximum sizes
1021 #define MAX_PACKET_SIZE 0x400 // anything beyond this needs to be fragmented
1022 #define MAX_PACKET_DATA_SIZE 0x7FC // for data packet (JavaLoader)
1024 /////////////////////////////////////////////////////////////////////////////
1026 // various useful sizes
1029 #define SB_PACKET_DBACCESS_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SB_DBACCESS_HEADER_SIZE)
1030 #define SB_FRAG_HEADER_SIZE SB_PACKET_DBACCESS_HEADER_SIZE
1032 #define SB_PACKET_COMMAND_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_COMMAND_HEADER_SIZE)
1033 #define SB_PACKET_RESPONSE_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_RESPONSE_HEADER_SIZE)
1035 #define SB_PACKET_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + DBDB_RECORD_HEADER_SIZE)
1036 #define SB_PACKET_OLD_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + OLD_DBDB_RECORD_HEADER_SIZE)
1038 #define SB_PACKET_UPLOAD_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + UPLOAD_HEADER_SIZE)
1040 #define SB_SEQUENCE_PACKET_SIZE (SB_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::SequenceCommand))
1041 #define SB_SOCKET_PACKET_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SOCKET_COMMAND_HEADER_SIZE)
1042 #define SB_MODE_PACKET_COMMAND_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::ModeSelect) - sizeof(::Barry::Protocol::ModeSelect::ResponseBlock))
1043 #define SB_MODE_PACKET_RESPONSE_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::ModeSelect))
1046 // Macros
1047 #define COMMAND(data) (((const ::Barry::Protocol::Packet *)data.GetData())->command)
1048 #define IS_COMMAND(data, cmd) (COMMAND(data) == cmd)
1049 #define MAKE_PACKET(var, data) const ::Barry::Protocol::Packet *var = (const ::Barry::Protocol::Packet *) (data).GetData()
1050 #define MAKE_JLPACKET(var, data) const ::Barry::Protocol::JLPacket *var = (const ::Barry::Protocol::JLPacket *) (data).GetData()
1051 #define MAKE_JVMPACKET(var, data) const ::Barry::Protocol::JVMPacket *var = (const ::Barry::Protocol::JVMPacket *) (data).GetData()
1052 #define MAKE_CHANNELPACKET(var, data) const ::Barry::Protocol::ChannelPacket *var = (const ::Barry::Protocol::ChannelPacket *) (data).GetData()
1053 #define MAKE_PACKETPTR_BUF(var, ptr) ::Barry::Protocol::Packet *var = (::Barry::Protocol::Packet *)ptr
1054 #define MAKE_JLPACKETPTR_BUF(var, ptr) ::Barry::Protocol::JLPacket *var = (::Barry::Protocol::JLPacket *)ptr
1055 #define MAKE_JVMPACKETPTR_BUF(var, ptr) ::Barry::Protocol::JVMPacket *var = (::Barry::Protocol::JVMPacket *)ptr
1056 #define MAKE_CHANNELPACKETPTR_BUF(var, ptr) ::Barry::Protocol::ChannelPacket *var = (::Barry::Protocol::ChannelPacket *)ptr
1057 #define MAKE_RECORD(type,var,data,off) type *var = (type *) ((data).GetData() + (off))
1058 #define MAKE_RECORD_PTR(type,var,data,off) type *var = (type *) ((data) + (off))
1060 // fragmentation protocol
1061 // send DATA first, then keep sending DATA packets, FRAGMENTing
1062 // as required until finished, then send DONE. Both sides behave
1063 // this way, so different sized data can be sent in both
1064 // directions
1066 // the fragmented piece only has a the param header, and then continues
1067 // right on with the data
1071 // checks packet size and throws BError if not right
1072 void CheckSize(const Barry::Data &packet, size_t requiredsize);
1073 unsigned int GetSize(const Barry::Data &packet);
1075 }} // namespace Barry::Protocol
1077 #endif