menu: added new Keywords tag to .desktop files
[barry.git] / src / protostructs.h
blobfb0df01747cb38080c1605d1af6480619678ff9c
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-2013, 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>
35 #include "platform.h" // safe to include platform.h here, since
36 // protostructs.h is not installed either
38 #if USE_PACK_PRAGMA
39 #pragma pack(push, 1)
40 #endif
42 // forward declarations
43 namespace Barry { class Data; }
45 namespace Barry { namespace Protocol {
47 ///////////////////////////////////////////////////////////////////////////////
48 union SizePacket
50 uint16_t size;
51 char buffer[4];
52 } ATTRIBUTE_PACKED;
55 ///////////////////////////////////////////////////////////////////////////////
56 // Record sub-field structs
58 struct GroupLink // used for Contacts records
60 uint32_t uniqueId;
61 uint16_t unknown;
62 } ATTRIBUTE_PACKED;
64 struct MessageAddress // used for Message records
66 uint8_t unknown[8];
67 uint8_t addr[1]; // 2 null terminated strings: first
68 // contains full name, second contains
69 // the email address
70 } ATTRIBUTE_PACKED;
73 ///////////////////////////////////////////////////////////////////////////////
74 // SMS Message field and record structures
76 struct SMSMetaData
78 uint8_t recv; // if received, this is set to 1; otherwise 0
79 uint8_t flags;
80 #define SMS_FLG_NEW_CONVERSATION 0x20
81 #define SMS_FLG_SAVED 0x10
82 #define SMS_FLG_DELETED 0x08
83 #define SMS_FLG_OPENED 0x01
85 uint8_t new_flag;
86 uint16_t zero; // constantly 0
87 uint32_t status;
88 #define SMS_STA_RECEIVED 0x000007ff
89 #define SMS_STA_DRAFT 0x7fffffff
91 uint32_t error_id;
92 uint64_t timestamp;
93 uint64_t service_center_timestamp;
94 uint8_t dcs;
95 #define SMS_DCS_7BIT 0x00
96 #define SMS_DCS_8BIT 0x01
97 #define SMS_DCS_UCS2 0x02
99 } ATTRIBUTE_PACKED;
100 #define SMS_METADATA_SIZE (sizeof(::Barry::Protocol::SMSMetaData))
104 ///////////////////////////////////////////////////////////////////////////////
105 // Record Field Formats
107 struct CommonField
109 uint16_t size; // including null terminator
110 uint8_t type;
112 union CommonFieldData
115 GroupLink link;
116 MessageAddress addr;
117 SMSMetaData sms_metadata;
118 uint64_t timestamp;
119 uint64_t uint64;
120 uint32_t uint32;
121 int32_t min1900;
122 uint16_t code;
123 uint8_t raw[1];
124 int16_t int16;
126 } ATTRIBUTE_PACKED u;
128 } ATTRIBUTE_PACKED;
129 #define COMMON_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::CommonField) - sizeof(::Barry::Protocol::CommonField::CommonFieldData))
130 #define COMMON_FIELD_MIN1900_SIZE (sizeof(int32_t))
132 struct CommandTableField
134 uint8_t size; // no null terminator
135 uint8_t code;
136 uint8_t name[1];
137 } ATTRIBUTE_PACKED;
138 #define COMMAND_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::CommandTableField) - 1)
140 struct OldDBDBField
142 uint16_t dbNumber;
143 uint8_t unknown1;
144 uint32_t dbSize; // assumed from Cassis docs...
145 // always 0 in USB
146 uint16_t dbRecordCount;
147 uint16_t unknown2;
148 uint16_t nameSize; // includes null terminator
149 uint8_t name[1];
150 } ATTRIBUTE_PACKED;
151 #define OLD_DBDB_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::OldDBDBField) - 1)
153 struct DBDBField
155 uint16_t dbNumber;
156 uint8_t unknown1;
157 uint32_t dbSize; // assumed from Cassis docs...
158 // always 0 in USB
159 uint32_t dbRecordCount;
160 uint16_t unknown2;
161 uint16_t nameSize; // includes null terminator
162 uint8_t unknown3;
163 uint8_t name[1]; // followed by 2 zeros!
164 uint16_t unknown; // this comes after the
165 // null terminated name, but
166 // is here for size calcs
167 } ATTRIBUTE_PACKED;
168 #define DBDB_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::DBDBField) - 1)
170 struct RecordStateTableField
172 uint8_t rectype; // it is unknown exactly what
173 // this field does, but it
174 // shows up here and in the
175 // tagged record header, and
176 // for some of the records
177 // they must match when writing
178 uint16_t index;
179 uint32_t uniqueId; // matches the uniqueId of say,
180 // address book records
181 uint8_t flags; // bit 0x01 is the dirty flag
182 // don't know if any other bits
183 // are used
184 #define BARRY_RSTF_DIRTY 0x01
185 uint8_t unknown2[4];
186 } ATTRIBUTE_PACKED;
188 struct CalendarRecurrenceDataField // as documented in the Cassis project spec
190 uint8_t type;
191 #define CRDF_TYPE_DAY 0x01
192 #define CRDF_TYPE_MONTH_BY_DATE 0x03
193 #define CRDF_TYPE_MONTH_BY_DAY 0x04
194 #define CRDF_TYPE_YEAR_BY_DATE 0x05
195 #define CRDF_TYPE_YEAR_BY_DAY 0x06
196 #define CRDF_TYPE_WEEK 0x0c
198 uint8_t unknown; // always 0x01
199 uint16_t interval;
200 uint32_t startTime;
201 uint32_t endTime; // 0xFFFFFFFF for never
203 union Additional
205 // Note: blank fields should be set to 0
207 struct Day
209 uint8_t day[6]; // always zeros!
210 } ATTRIBUTE_PACKED day;
212 struct MonthByDate
214 uint8_t monthDay; // day of month to recur on
215 // (1-31)
216 uint8_t blank[5];
217 } ATTRIBUTE_PACKED month_by_date;
219 struct MonthByDay
221 uint8_t weekDay; // day of week to recur on (0-6)
222 uint8_t week; // week of month to recur on
223 // (1 to 5, first week, second
224 // week, etc)
225 uint8_t blank[4];
226 } ATTRIBUTE_PACKED month_by_day;
228 struct YearByDate
230 uint8_t monthDay; // day of month to recur on
231 // (1-31)
232 uint8_t blank;
233 uint8_t month; // month to recur on (1-12)
234 uint8_t blank_[3];
235 } ATTRIBUTE_PACKED year_by_date;
237 struct YearByDay
239 uint8_t weekDay; // day of week to recur on (0-6)
240 uint8_t week; // week of month (1 to 5)
241 uint8_t month; // (1-12)
242 uint8_t blank[3];
243 } ATTRIBUTE_PACKED year_by_day;
245 struct Week
247 uint8_t days; // bitmask
248 #define CRDF_WD_SUN 0x01
249 #define CRDF_WD_MON 0x02
250 #define CRDF_WD_TUE 0x04
251 #define CRDF_WD_WED 0x08
252 #define CRDF_WD_THU 0x10
253 #define CRDF_WD_FRI 0x20
254 #define CRDF_WD_SAT 0x40
256 uint8_t blank[5];
257 } ATTRIBUTE_PACKED week;
259 } ATTRIBUTE_PACKED u;
261 } ATTRIBUTE_PACKED;
262 #define CALENDAR_RECURRENCE_DATA_FIELD_SIZE sizeof(::Barry::Protocol::CalendarRecurrenceDataField)
265 // Calendar record: field constants
268 #define CR_FREEBUSY_FREE 0
269 #define CR_FREEBUSY_TENTATIVE 1
270 #define CR_FREEBUSY_BUSY 2
271 #define CR_FREEBUSY_OUT_OF_OFFICE 3
272 #define CR_FREEBUSY_RANGE_LOW 0
273 #define CR_FREEBUSY_RANGE_HIGH 3
275 #define CR_CLASS_PUBLIC 0
276 #define CR_CLASS_CONFIDENTIAL 1
277 #define CR_CLASS_PRIVATE 2
278 #define CR_CLASS_RANGE_LOW 0
279 #define CR_CLASS_RANGE_HIGH 2
283 // Task record: field constants
286 #define TR_ALARM_DATE 1
287 #define TR_ALARM_RELATIVE 2
288 #define TR_ALARM_RANGE_LOW 1
289 #define TR_ALARM_RANGE_HIGH 2
291 #define TR_PRIORITY_HIGH 0
292 #define TR_PRIORITY_NORMAL 1
293 #define TR_PRIORITY_LOW 2
294 #define TR_PRIORITY_RANGE_LOW 0
295 #define TR_PRIORITY_RANGE_HIGH 2
297 #define TR_STATUS_NOT_STARTED 0
298 #define TR_STATUS_IN_PROGRESS 1
299 #define TR_STATUS_COMPLETED 2
300 #define TR_STATUS_WAITING 3
301 #define TR_STATUS_DEFERRED 4
302 #define TR_STATUS_RANGE_LOW 0
303 #define TR_STATUS_RANGE_HIGH 4
306 // Phone Call Logs record: field constants
309 #define CLL_DIRECTION_RECEIVER 0
310 #define CLL_DIRECTION_EMITTER 1
311 #define CLL_DIRECTION_FAILED 2
312 #define CLL_DIRECTION_MISSING 3
313 #define CLL_DIRECTION_RANGE_LOW 0
314 #define CLL_DIRECTION_RANGE_HIGH 3
316 #define CLL_PHONETYPE_UNDEFINED 0
317 #define CLL_PHONETYPE_OFFICE 1
318 #define CLL_PHONETYPE_HOME 2
319 #define CLL_PHONETYPE_MOBILE 3
320 #define CLL_PHONETYPE_RANGE_LOW 0
321 #define CLL_PHONETYPE_RANGE_HIGH 3
324 // Browser Bookmarks record: field constants
327 #define BMK_BROWSER_AUTO 0
328 #define BMK_BROWSER_BLACKBERRY 1
329 #define BMK_BROWSER_FIREFOX 2
330 #define BMK_BROWSER_INTERNET_EXPLORER 3
332 #define BMK_DISPLAY_AUTO 0
333 #define BMK_DISPLAY_COLOMN 1
334 #define BMK_DISPLAY_PAGE 2
336 #define BMK_JAVASCRIPT_AUTO 0
337 #define BMK_JAVASCRIPT_ENABLED 1
338 #define BMK_JAVASCRIPT_DISABLED 2
340 struct StringField
342 uint16_t be_size; // may or may not have a null term.
343 // big-endian
344 uint8_t data[1];
345 } ATTRIBUTE_PACKED;
346 #define STRING_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::StringField) - 1)
348 struct BookmarkId
350 uint32_t bookmark_id;
351 uint8_t index;
352 } ATTRIBUTE_PACKED;
353 #define BOOKMARK_ID_SIZE (sizeof(::Barry::Protocol::BookmarkId))
355 struct VarStringField
357 uint8_t present;
358 uint16_t be_size; // big-endian
359 uint8_t data[1];
360 } ATTRIBUTE_PACKED;
361 #define VARSTRING_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::VarStringField) - 1)
363 struct BookmarkFolders
365 uint32_t id1; // these two fields contain
366 uint32_t id2; // b9 fc f8 f6 c2 e3 a4 d5
367 // whenever there is a record in
368 // the Blackberry Bookmarks folder,
369 // even across multiple devices!
370 // this was true for the 9550 and
371 // the oooold 7750, and the 8700
372 uint8_t unknown; // may be a section code? seems to
373 // always be 0x08
374 uint8_t flag; // unknown flag
375 } ATTRIBUTE_PACKED;
376 #define BOOKMARK_FOLDERS_HEADER_SIZE (sizeof(::Barry::Protocol::BookmarkFolders))
380 // Folder record: field constants
383 #define FR_TYPE_SUBTREE 0x00
384 #define FR_TYPE_DELETED 0x01
385 #define FR_TYPE_INBOX 0x02
386 #define FR_TYPE_OUTBOX 0x03
387 #define FR_TYPE_SENT 0x04
388 #define FR_TYPE_OTHER 0x05
389 #define FR_TYPE_DRAFT 0x0a
391 #define FR_STATUS_ORPHAN 0x50
392 #define FR_STATUS_UNFILED 0x51
393 #define FR_STATUS_FILED 0x52
396 ///////////////////////////////////////////////////////////////////////////////
397 // Packed field structures - odd format used with Service Book records
399 struct PackedField_02
401 uint8_t code;
402 uint8_t size;
403 uint8_t type;
404 uint8_t raw[1];
405 } ATTRIBUTE_PACKED;
406 #define PACKED_FIELD_02_HEADER_SIZE (sizeof(::Barry::Protocol::PackedField_02) - 1)
408 struct PackedField_10
410 uint8_t type;
411 uint8_t size;
412 uint8_t raw[1];
413 } ATTRIBUTE_PACKED;
414 #define PACKED_FIELD_10_HEADER_SIZE (sizeof(::Barry::Protocol::PackedField_10) - 1)
419 ///////////////////////////////////////////////////////////////////////////////
420 // Service Book field and record structures
422 struct ServiceBookConfigField
424 uint8_t format;
425 uint8_t fields[1];
426 } ATTRIBUTE_PACKED;
427 #define SERVICE_BOOK_CONFIG_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::ServiceBookConfigField) - 1)
430 ///////////////////////////////////////////////////////////////////////////////
431 // DB Command Parameter structures
433 struct DBC_Record
435 uint16_t recordIndex; // index comes from RecordStateTable
436 uint8_t data[1];
437 } ATTRIBUTE_PACKED;
438 #define DBC_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBC_Record) - 1)
440 struct DBC_RecordFlags
442 uint8_t unknown;
443 uint16_t index;
444 uint8_t unknown2[5];
445 } ATTRIBUTE_PACKED;
446 #define DBC_RECORD_FLAGS_SIZE (sizeof(::Barry::Protocol::DBC_RecordFlags))
448 struct DBC_TaggedUpload
450 uint8_t rectype; // it is unknown exactly what
451 // this field does, but it
452 // shows up here and in the
453 // RecordStateTable, and
454 // for some of the records
455 // they must match when writing
456 uint32_t uniqueId;
457 uint8_t unknown2;
458 uint8_t data[1];
459 } ATTRIBUTE_PACKED;
460 #define DBC_TAGGED_UPLOAD_HEADER_SIZE (sizeof(::Barry::Protocol::DBC_TaggedUpload) - 1)
462 struct DBC_IndexedUpload
464 uint8_t unknown; // observed: 00 or 05
465 uint16_t index;
466 uint8_t data[1];
467 } ATTRIBUTE_PACKED;
468 #define DBC_INDEXED_UPLOAD_HEADER_SIZE (sizeof(::Barry::Protocol::DBC_IndexedUpload) - 1)
470 struct PasswordChallenge
472 uint8_t remaining_tries; // number of password attempts
473 // the device will accept before
474 // committing suicide...
475 // starts at 10 and counts down
476 // on each bad password
477 uint8_t unknown; // observed as 0... probably just
478 // the top byte of a uint16
479 // remaining_tries, but I don't
480 // want to take that chance
481 uint16_t param; // seems to be a secondary command
482 // of some kind, observed as 0x14
483 // or 0x04, but purpose unknown
484 // possibly a send/receive flag
485 // bit (0x10/0x00)
486 union Hash
488 uint32_t seed;
489 uint8_t hash[20];
490 } ATTRIBUTE_PACKED u;
492 } ATTRIBUTE_PACKED;
493 #define PASSWORD_CHALLENGE_HEADER_SIZE (sizeof(::Barry::Protocol::PasswordChallenge) - sizeof(::Barry::Protocol::PasswordChallenge::Hash))
494 #define PASSWORD_CHALLENGE_SEED_SIZE (PASSWORD_CHALLENGE_HEADER_SIZE + sizeof(uint32_t))
495 #define PASSWORD_CHALLENGE_SIZE (sizeof(::Barry::Protocol::PasswordChallenge))
497 struct AttributeFetch
499 uint16_t object;
500 uint16_t attribute;
501 uint8_t raw[1]; // used only in response
502 } ATTRIBUTE_PACKED;
503 #define ATTRIBUTE_FETCH_COMMAND_SIZE (sizeof(::Barry::Protocol::AttributeFetch) - 1)
505 struct ModeSelect
507 uint8_t name[16];
508 struct ResponseBlock
510 uint8_t unknown[20];
511 } ATTRIBUTE_PACKED response;
512 } ATTRIBUTE_PACKED;
514 struct Echo
516 uint64_t ticks; // number of microseconds since
517 // host system startup
518 } ATTRIBUTE_PACKED;
519 #define ECHO_COMMAND_SIZE (sizeof(::Barry::Protocol::Echo))
522 ///////////////////////////////////////////////////////////////////////////////
523 // Protocol command structures
525 struct SocketCommand
527 uint16_t socket;
528 uint8_t sequence; // incremented on each socket 0
529 // communication, replies return
530 // the same number from command
532 union PacketData
535 PasswordChallenge password;
536 AttributeFetch fetch;
537 ModeSelect mode;
538 uint8_t raw[1];
539 Echo echo;
541 } ATTRIBUTE_PACKED u;
542 } ATTRIBUTE_PACKED;
543 #define SOCKET_COMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::SocketCommand) - sizeof(::Barry::Protocol::SocketCommand::PacketData))
545 struct SequenceCommand
547 uint8_t socket; // socket number, single byte
548 uint8_t unknown2;
549 uint8_t unknown3;
550 uint32_t sequenceId;
551 } ATTRIBUTE_PACKED;
553 struct DBCommand
555 uint8_t operation; // see below
556 uint16_t databaseId; // value from the Database Database
558 union Parameters
561 DBC_Record record;
562 DBC_RecordFlags flags;
563 DBC_TaggedUpload tag_upload;
564 DBC_IndexedUpload index_upload;
565 uint8_t raw[1];
567 } ATTRIBUTE_PACKED u;
568 } ATTRIBUTE_PACKED;
569 #define DB_COMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::DBCommand) - sizeof(::Barry::Protocol::DBCommand::Parameters))
573 ///////////////////////////////////////////////////////////////////////////////
574 // Protocol response parameter structures
576 struct DBR_OldDBDBRecord
578 uint16_t count; // number of fields in record
579 OldDBDBField field[1];
580 } ATTRIBUTE_PACKED;
581 #define OLD_DBDB_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBR_OldDBDBRecord) - sizeof(::Barry::Protocol::OldDBDBField))
583 struct DBR_DBDBRecord
585 uint16_t count;
586 uint8_t unknown[3];
587 DBDBField field[1];
588 } ATTRIBUTE_PACKED;
589 #define DBDB_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBR_DBDBRecord) - sizeof(::Barry::Protocol::DBDBField))
591 // Records with a uniqueId. This covers the following records:
593 // Old Contact records
594 // Old Service Book records
595 // Old Calendar records
597 struct DBR_OldTaggedRecord
599 uint8_t rectype;
600 uint16_t index;
601 uint32_t uniqueId;
602 uint8_t unknown2;
604 union TaggedData
606 CommonField field[1];
607 } ATTRIBUTE_PACKED u;
608 } ATTRIBUTE_PACKED;
609 #define DBR_OLD_TAGGED_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBR_OldTaggedRecord) - sizeof(::Barry::Protocol::DBR_OldTaggedRecord::TaggedData))
611 struct MessageRecord
613 uint8_t field1; // always 'j'
614 uint32_t field2; // always 0x00000000
615 uint32_t flags; // flags
616 uint32_t field4; // normal email and pin recv this is 0x7ff
617 // changes on sent and reply to 0x01ffffff
618 // and 0x003fffff on pin send
619 uint32_t field5; // always 0x00000000
620 uint32_t field6; // always 0x00000000
621 uint32_t field7; // always 0x00000000
622 uint32_t field8; // always 0x00000000
623 uint16_t field9; // always 0x0000
625 uint16_t dateReceived; // the first two of these time fields are always the same
626 uint16_t timeReceived; //
627 uint16_t dateDuplicate; // On mail sent from the BB all three fields are identical
628 uint16_t timeDuplicate; // (time sent)
629 uint16_t dateSent;
630 uint16_t timeSent;
632 uint16_t priority; // priority field
633 uint32_t field14; // always 0x00000000
634 uint32_t field15; // always 0x00000000
635 uint16_t field16; // always 0x0000
636 uint32_t field13; // PIN reply 0x00000000 other time 0xffffffff or 0xfffffffe
637 uint16_t messageSize; // Message size, 0x0000 if Reply or Saved, 0xffff if below ????
638 uint32_t field18; // 0x0's and 0xF'x
639 uint32_t field19; // 0x0's and 0xF's
640 uint16_t field20; // always 0x0000
641 uint16_t field21; // 0x01 unless PIN reply then 0x00
642 uint32_t inReplyTo; // reply to message?
643 uint32_t field22; // always 0x00000000
644 uint16_t field23; // FIXME
646 uint32_t folderOne; // these are the 'folders' the message is in
647 uint32_t folderTwo; //
649 uint16_t replyMessageFlags; // 0xfffe on recvd messages
650 // 0x001b on reply
651 // 0x0015 on send
652 // 0x3 pin send
653 // 0x2 on pin recv
654 uint16_t field27; // set to 0x00000004 on PIN reply, 0x00000005 otherwise
655 uint32_t headerUID; // yet another copy of the UID (RecId)
657 uint32_t field29; // always 0x00000000
658 uint16_t field30; // always 0x0002
659 uint16_t field31; // always 0x00000000
660 uint16_t field32; // always 0x0004
661 uint16_t field34; // always 0x0000
662 uint8_t field33; // always 'd'
663 uint32_t timeBlock; // FIXME
664 CommonField field[1];
665 } ATTRIBUTE_PACKED;
666 #define MESSAGE_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::MessageRecord) - sizeof(::Barry::Protocol::CommonField))
670 ///////////////////////////////////////////////////////////////////////////////
671 // Protocol response structures
673 struct DBResponse
675 uint8_t operation;
677 union Parameters
680 DBR_OldTaggedRecord tagged;
681 DBR_OldDBDBRecord old_dbdb;
682 DBR_DBDBRecord dbdb;
684 } ATTRIBUTE_PACKED u;
686 } ATTRIBUTE_PACKED;
687 #define DB_RESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::DBResponse) - sizeof(::Barry::Protocol::DBResponse::Parameters))
691 ///////////////////////////////////////////////////////////////////////////////
692 // Database access command structure
694 // even fragmented packets have a tableCmd
695 struct DBAccess
697 uint8_t tableCmd;
699 union DBData
701 DBCommand command;
702 DBResponse response;
703 CommandTableField table[1];
704 uint8_t return_code;
705 uint8_t fragment[1];
707 } ATTRIBUTE_PACKED u;
708 } ATTRIBUTE_PACKED;
709 #define SB_DBACCESS_HEADER_SIZE (sizeof(::Barry::Protocol::DBAccess) - sizeof(::Barry::Protocol::DBAccess::DBData))
710 #define SB_DBACCESS_RETURN_CODE_SIZE (1)
714 ///////////////////////////////////////////////////////////////////////////////
715 // Javaloader protocol structure
717 struct JLDirEntry
719 uint16_t unknown;
720 uint32_t timestamp;
721 uint16_t filename_size;
722 uint8_t filename[1];
723 // the rest of the packet is variable length
724 // another string for version, then:
725 // uint32_t cod_size;
727 } ATTRIBUTE_PACKED;
728 #define SB_JLDIRENTRY_HEADER_SIZE (sizeof(::Barry::Protocol::JLDirEntry) - 1)
730 struct JLCommand
732 uint8_t command;
733 uint8_t unknown; // nearly always 0, might be top half of command
734 uint16_t size;
735 } ATTRIBUTE_PACKED;
736 #define SB_JLCOMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::JLCommand))
738 struct JLResponse
740 uint8_t command;
741 uint8_t unknown;
742 uint16_t expect;
743 } ATTRIBUTE_PACKED;
744 #define SB_JLRESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::JLResponse))
746 struct JLScreenInfo
748 uint16_t unknown1;
749 uint16_t unknown2;
750 uint16_t unknown3;
751 uint16_t width;
752 uint16_t height;
753 uint16_t unknown4;
754 uint16_t unknown5;
755 uint16_t unknown6;
756 } ATTRIBUTE_PACKED;
757 #define SB_JLSCREENINFO_SIZE (sizeof(::Barry::Protocol::JLScreenInfo))
759 struct JLEventlogEntry
761 uint16_t size;
762 // remainder of packet is variable
763 // it contains the log data as an ASCII (UTF-8?) string
764 } ATTRIBUTE_PACKED;
765 #define SB_JLEVENTLOG_ENTRY_HEADER_SIZE (sizeof(::Barry::Protocol::JLEventlogEntry))
767 struct JLDeviceInfo
769 uint32_t hardware_id;
770 uint32_t pin;
771 uint32_t os_version;
772 uint32_t vm_version;
773 uint32_t radio_id;
774 uint32_t vendor_id;
775 uint32_t active_wafs;
776 // older devices (such as 7130) don't this extra data in the
777 // device info packet and will therefore fail the size check
778 //uint8_t raw[4];
779 } ATTRIBUTE_PACKED;
780 #define SB_JLDEVICEINFO_SIZE (sizeof(::Barry::Protocol::JLDeviceInfo))
782 struct JLPacket
784 uint16_t socket;
785 uint16_t size; // total size of data packet
787 union PacketData
789 JLCommand command;
790 JLResponse response;
791 JLScreenInfo screeninfo;
792 JLEventlogEntry logentry;
793 JLDeviceInfo devinfo;
794 uint8_t raw[1];
795 char filename[1];
796 uint32_t cod_size;
797 uint32_t timestamp;
798 uint16_t id;
799 } ATTRIBUTE_PACKED u;
801 } ATTRIBUTE_PACKED;
802 #define SB_JLPACKET_HEADER_SIZE (sizeof(::Barry::Protocol::JLPacket) - sizeof(::Barry::Protocol::JLPacket::PacketData))
805 ///////////////////////////////////////////////////////////////////////////////
806 // JavaDebug protocol structures
808 namespace JDWP {
810 // Packet command
811 //----------------
813 struct PacketEventRequestSet {
814 uint8_t eventKind;
815 uint8_t suspendPolicy;
816 uint32_t modifiers;
817 } ATTRIBUTE_PACKED;
820 struct PacketEventRequest {
821 union PacketEventRequestData {
822 PacketEventRequestSet set;
823 } ATTRIBUTE_PACKED u;
824 } ATTRIBUTE_PACKED;
827 struct PacketCommand {
828 uint8_t commandset;
829 uint8_t command;
831 union PacketCommandData {
832 PacketEventRequest eventRequest;
833 } ATTRIBUTE_PACKED u;
834 } ATTRIBUTE_PACKED;
835 #define JDWP_COMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::JDWP::PacketCommand))
838 // Packet response
839 //-----------------
841 struct PacketVirtualMachineIDSizes {
842 uint32_t fieldIDSize;
843 uint32_t methodIDSize;
844 uint32_t objectIDSize;
845 uint32_t referenceTypeIDSize;
846 uint32_t frameIDSize;
847 } ATTRIBUTE_PACKED;
849 #define JDWP_PACKETVIRTUALMACHINEIDSIZES_DATA_SIZE sizeof(::Barry::Protocol::JDWP::PacketVirtualMachineIDSizes)
852 struct PacketVirtualMachine {
853 union PacketVirtualMachineData {
854 PacketVirtualMachineIDSizes IDSizes;
855 } ATTRIBUTE_PACKED u;
856 } ATTRIBUTE_PACKED;
859 struct PacketResponse {
860 uint16_t errorcode;
862 union PacketResponseData {
863 PacketVirtualMachine virtualMachine;
864 uint32_t value;
865 uint8_t raw[1];
866 } ATTRIBUTE_PACKED u;
867 } ATTRIBUTE_PACKED;
868 #define JDWP_RESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::JDWP::PacketResponse) - sizeof(::Barry::Protocol::JDWP::PacketResponse::PacketResponseData))
871 // Generic packet
872 //----------------
874 struct Packet {
875 uint32_t length;
876 uint32_t id;
877 uint8_t flags;
879 union PacketType {
880 PacketCommand command;
881 PacketResponse response;
882 } ATTRIBUTE_PACKED u;
883 } ATTRIBUTE_PACKED;
884 #define JDWP_PACKET_HEADER_SIZE (sizeof(::Barry::Protocol::JDWP::Packet) - sizeof(::Barry::Protocol::JDWP::Packet::PacketType))
887 #define MAKE_JDWPPACKET(var, data) const ::Barry::Protocol::JDWP::Packet *var = (const ::Barry::Protocol::JDWP::Packet *) (data).GetData()
888 #define MAKE_JDWPPACKETPTR_BUF(var, ptr) ::Barry::Protocol::JDWP::Packet *var = (::Barry::Protocol::JDWP::Packet *)ptr
891 } // namespace JDWP
893 struct JDWField {
894 uint32_t size;
896 union JDWFieldData {
897 uint8_t raw[1];
898 } ATTRIBUTE_PACKED u;
899 } ATTRIBUTE_PACKED;
900 #define JDWP_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::JDWField) - sizeof(::Barry::Protocol::JDWField::JDWFieldData))
902 struct JVMCommand
904 uint16_t size;
905 uint8_t command;
906 uint8_t raw[1];
907 } ATTRIBUTE_PACKED;
908 #define SB_JVMCOMMAND_HEADER_SIZE (sizeof(::Barry::Protocol::JVMCommand))
910 struct JVMResponse
912 uint8_t command;
913 uint8_t unknown;
914 uint16_t expect;
915 } ATTRIBUTE_PACKED;
916 #define SB_JVMRESPONSE_HEADER_SIZE (sizeof(::Barry::Protocol::JVMResponse))
918 struct JVMModulesList
920 uint32_t nbr;
921 // remainder of packet is variable
922 // it contains the modules list
923 } ATTRIBUTE_PACKED;
924 #define SB_JVMMODULES_LIST_HEADER_SIZE (sizeof(::Barry::Protocol::JVMModulesList))
926 struct JVMModulesEntry
928 uint32_t id;
929 uint32_t uniqueId;
930 uint16_t sizename;
931 // remainder of packet is variable
932 // it contains the module name
933 } ATTRIBUTE_PACKED;
934 #define SB_JVMMODULES_ENTRY_HEADER_SIZE (sizeof(::Barry::Protocol::JVMModulesEntry))
936 struct JVMThreadsList
938 uint32_t nbr;
939 // remainder of packet is variable
940 // it contains the threads list
941 } ATTRIBUTE_PACKED;
942 #define SB_JVMTHREADS_LIST_HEADER_SIZE (sizeof(::Barry::Protocol::JVMThreadsList))
944 struct JVMUnknown01
946 uint8_t byte;
947 uint32_t address;
948 } ATTRIBUTE_PACKED;
949 #define SB_JVMUNKNOWN01_HEADER_SIZE (sizeof(::Barry::Protocol::JVMUnknown01))
951 struct JVMUnknown02
953 uint32_t address1;
954 uint32_t address2;
955 } ATTRIBUTE_PACKED;
956 #define SB_JVMUNKNOWN02_HEADER_SIZE (sizeof(::Barry::Protocol::JVMUnknown02))
958 struct JVMPacket
960 uint16_t socket;
961 uint16_t size; // total size of data packet
963 union PacketData
965 JVMCommand command;
966 JVMResponse response;
967 JVMModulesList moduleslist;
968 JVMThreadsList threadslist;
969 JVMUnknown01 unknown01;
970 JVMUnknown02 unknown02;
971 uint32_t address;
972 uint16_t expect;
973 uint16_t msglength;
974 uint16_t value;
975 uint8_t status;
976 uint8_t raw[1];
977 } ATTRIBUTE_PACKED u;
979 } ATTRIBUTE_PACKED;
980 #define SB_JVMPACKET_HEADER_SIZE (sizeof(::Barry::Protocol::JVMPacket) - sizeof(::Barry::Protocol::JVMPacket::PacketData))
983 /////////////////////////////////////////////////////////////////////////////
984 // Raw channel packet structure
985 struct ChannelPacket
987 uint16_t socket; // socket ID... 0 exists by default
988 uint16_t size; // total size of data packet
990 union PacketData
992 uint8_t data[1];
993 } ATTRIBUTE_PACKED u;
994 } ATTRIBUTE_PACKED;
995 #define SB_CHANNELPACKET_HEADER_SIZE (sizeof(::Barry::Protocol::ChannelPacket) - sizeof(::Barry::Protocol::ChannelPacket::PacketData))
997 #define SB_CHANNELPACKET_MAX_DATA_SIZE 0x3FFC
999 ///////////////////////////////////////////////////////////////////////////////
1000 // Main packet struct
1002 struct Packet
1004 uint16_t socket; // socket ID... 0 exists by default
1005 uint16_t size; // total size of data packet
1006 uint8_t command;
1008 union PacketData
1011 SocketCommand socket;
1012 SequenceCommand sequence;
1013 DBAccess db;
1014 uint8_t raw[1];
1016 } ATTRIBUTE_PACKED u;
1017 } ATTRIBUTE_PACKED;
1018 #define SB_PACKET_SOCKET_SIZE (sizeof(uint16_t)) // size needed to read the socket in a packet
1019 #define SB_PACKET_HEADER_SIZE (sizeof(::Barry::Protocol::Packet) - sizeof(::Barry::Protocol::Packet::PacketData))
1021 // WARNING : For JavaLoader we have some packet with 5 size !
1022 #define MIN_PACKET_SIZE 5
1023 #define MIN_PACKET_DATA_SIZE 4
1026 // maximum sizes
1027 #define MAX_PACKET_SIZE 0x400 // anything beyond this needs to be fragmented
1028 #define MAX_PACKET_DATA_SIZE 0x7FC // for data packet (JavaLoader)
1030 /////////////////////////////////////////////////////////////////////////////
1032 // various useful sizes
1035 #define SB_PACKET_DBACCESS_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SB_DBACCESS_HEADER_SIZE)
1036 #define SB_FRAG_HEADER_SIZE SB_PACKET_DBACCESS_HEADER_SIZE
1038 #define SB_PACKET_COMMAND_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_COMMAND_HEADER_SIZE)
1039 #define SB_PACKET_RESPONSE_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_RESPONSE_HEADER_SIZE)
1041 #define SB_PACKET_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + DBDB_RECORD_HEADER_SIZE)
1042 #define SB_PACKET_OLD_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + OLD_DBDB_RECORD_HEADER_SIZE)
1044 #define SB_PACKET_UPLOAD_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + UPLOAD_HEADER_SIZE)
1046 #define SB_SEQUENCE_PACKET_SIZE (SB_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::SequenceCommand))
1047 #define SB_SOCKET_PACKET_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SOCKET_COMMAND_HEADER_SIZE)
1048 #define SB_MODE_PACKET_COMMAND_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::ModeSelect) - sizeof(::Barry::Protocol::ModeSelect::ResponseBlock))
1049 #define SB_MODE_PACKET_RESPONSE_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::ModeSelect))
1052 // Macros
1053 #define COMMAND(data) (((const ::Barry::Protocol::Packet *)data.GetData())->command)
1054 #define IS_COMMAND(data, cmd) (COMMAND(data) == cmd)
1055 #define MAKE_PACKET(var, data) const ::Barry::Protocol::Packet *var = (const ::Barry::Protocol::Packet *) (data).GetData()
1056 #define MAKE_JLPACKET(var, data) const ::Barry::Protocol::JLPacket *var = (const ::Barry::Protocol::JLPacket *) (data).GetData()
1057 #define MAKE_JVMPACKET(var, data) const ::Barry::Protocol::JVMPacket *var = (const ::Barry::Protocol::JVMPacket *) (data).GetData()
1058 #define MAKE_CHANNELPACKET(var, data) const ::Barry::Protocol::ChannelPacket *var = (const ::Barry::Protocol::ChannelPacket *) (data).GetData()
1059 #define MAKE_PACKETPTR_BUF(var, ptr) ::Barry::Protocol::Packet *var = (::Barry::Protocol::Packet *)ptr
1060 #define MAKE_JLPACKETPTR_BUF(var, ptr) ::Barry::Protocol::JLPacket *var = (::Barry::Protocol::JLPacket *)ptr
1061 #define MAKE_JVMPACKETPTR_BUF(var, ptr) ::Barry::Protocol::JVMPacket *var = (::Barry::Protocol::JVMPacket *)ptr
1062 #define MAKE_CHANNELPACKETPTR_BUF(var, ptr) ::Barry::Protocol::ChannelPacket *var = (::Barry::Protocol::ChannelPacket *)ptr
1063 #define MAKE_RECORD(type,var,data,off) type *var = (type *) ((data).GetData() + (off))
1064 #define MAKE_RECORD_PTR(type,var,data,off) type *var = (type *) ((data) + (off))
1066 // fragmentation protocol
1067 // send DATA first, then keep sending DATA packets, FRAGMENTing
1068 // as required until finished, then send DONE. Both sides behave
1069 // this way, so different sized data can be sent in both
1070 // directions
1072 // the fragmented piece only has a the param header, and then continues
1073 // right on with the data
1077 // checks packet size and throws BError if not right
1078 void CheckSize(const Barry::Data &packet, size_t requiredsize);
1079 unsigned int GetSize(const Barry::Data &packet);
1081 bool IsSequencePacket(const Barry::Data &data);
1083 }} // namespace Barry::Protocol
1085 #if USE_PACK_PRAGMA
1086 #pragma pack(pop)
1087 #endif
1089 #endif