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.
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.
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__
34 #include <sys/types.h>
36 // forward declarations
37 namespace Barry
{ class Data
; }
39 namespace Barry
{ namespace Protocol
{
41 ///////////////////////////////////////////////////////////////////////////////
46 } __attribute__ ((packed
));
49 ///////////////////////////////////////////////////////////////////////////////
50 // Record sub-field structs
52 struct GroupLink
// used for Contacts records
56 } __attribute__ ((packed
));
58 struct MessageAddress
// used for Message records
61 uint8_t addr
[1]; // 2 null terminated strings: first
62 // contains full name, second contains
64 } __attribute__ ((packed
));
67 ///////////////////////////////////////////////////////////////////////////////
68 // SMS Message field and record structures
72 uint8_t recv
; // if received, this is set to 1; otherwise 0
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
80 uint16_t zero
; // constantly 0
82 #define SMS_STA_RECEIVED 0x000007ff
83 #define SMS_STA_DRAFT 0x7fffffff
87 uint64_t service_center_timestamp
;
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
103 uint16_t size
; // including null terminator
106 union CommonFieldData
111 SMSMetaData sms_metadata
;
119 } __attribute__ ((packed
)) u
;
121 } __attribute__ ((packed
));
122 #define COMMON_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::CommonField) - sizeof(Barry::Protocol::CommonField::CommonFieldData))
123 #define COMMON_FIELD_MIN1900_SIZE (sizeof(int32_t))
125 struct CommandTableField
127 uint8_t size
; // no null terminator
130 } __attribute__ ((packed
));
131 #define COMMAND_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::CommandTableField) - 1)
137 uint32_t dbSize
; // assumed from Cassis docs...
139 uint16_t dbRecordCount
;
141 uint16_t nameSize
; // includes null terminator
143 } __attribute__ ((packed
));
144 #define OLD_DBDB_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::OldDBDBField) - 1)
150 uint32_t dbSize
; // assumed from Cassis docs...
152 uint32_t dbRecordCount
;
154 uint16_t nameSize
; // includes null terminator
156 uint8_t name
[1]; // followed by 2 zeros!
157 uint16_t unknown
; // this comes after the
158 // null terminated name, but
159 // is here for size calcs
160 } __attribute__ ((packed
));
161 #define DBDB_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::DBDBField) - 1)
163 struct RecordStateTableField
165 uint8_t rectype
; // it is unknown exactly what
166 // this field does, but it
167 // shows up here and in the
168 // tagged record header, and
169 // for some of the records
170 // they must match when writing
172 uint32_t uniqueId
; // matches the uniqueId of say,
173 // address book records
174 uint8_t flags
; // bit 0x01 is the dirty flag
175 // don't know if any other bits
177 #define BARRY_RSTF_DIRTY 0x01
179 } __attribute__ ((packed
));
181 struct CalendarRecurrenceDataField
// as documented in the Cassis project spec
184 #define CRDF_TYPE_DAY 0x01
185 #define CRDF_TYPE_MONTH_BY_DATE 0x03
186 #define CRDF_TYPE_MONTH_BY_DAY 0x04
187 #define CRDF_TYPE_YEAR_BY_DATE 0x05
188 #define CRDF_TYPE_YEAR_BY_DAY 0x06
189 #define CRDF_TYPE_WEEK 0x0c
191 uint8_t unknown
; // always 0x01
194 uint32_t endTime
; // 0xFFFFFFFF for never
198 // Note: blank fields should be set to 0
202 uint8_t day
[6]; // always zeros!
203 } __attribute__ ((packed
)) day
;
207 uint8_t monthDay
; // day of month to recur on
210 } __attribute__ ((packed
)) month_by_date
;
214 uint8_t weekDay
; // day of week to recur on (0-6)
215 uint8_t week
; // week of month to recur on
216 // (1 to 5, first week, second
219 } __attribute__ ((packed
)) month_by_day
;
223 uint8_t monthDay
; // day of month to recur on
226 uint8_t month
; // month to recur on (1-12)
228 } __attribute__ ((packed
)) year_by_date
;
232 uint8_t weekDay
; // day of week to recur on (0-6)
233 uint8_t week
; // week of month (1 to 5)
234 uint8_t month
; // (1-12)
236 } __attribute__ ((packed
)) year_by_day
;
240 uint8_t days
; // bitmask
241 #define CRDF_WD_SUN 0x01
242 #define CRDF_WD_MON 0x02
243 #define CRDF_WD_TUE 0x04
244 #define CRDF_WD_WED 0x08
245 #define CRDF_WD_THU 0x10
246 #define CRDF_WD_FRI 0x20
247 #define CRDF_WD_SAT 0x40
250 } __attribute__ ((packed
)) week
;
252 } __attribute__ ((packed
)) u
;
254 } __attribute__ ((packed
));
255 #define CALENDAR_RECURRENCE_DATA_FIELD_SIZE sizeof(Barry::Protocol::CalendarRecurrenceDataField)
258 // Calendar record: field constants
261 #define CR_FREEBUSY_FREE 0
262 #define CR_FREEBUSY_TENTATIVE 1
263 #define CR_FREEBUSY_BUSY 2
264 #define CR_FREEBUSY_OUT_OF_OFFICE 3
265 #define CR_FREEBUSY_RANGE_LOW 0
266 #define CR_FREEBUSY_RANGE_HIGH 3
268 #define CR_CLASS_PUBLIC 0
269 #define CR_CLASS_CONFIDENTIAL 1
270 #define CR_CLASS_PRIVATE 2
271 #define CR_CLASS_RANGE_LOW 0
272 #define CR_CLASS_RANGE_HIGH 2
276 // Task record: field constants
279 #define TR_ALARM_DATE 1
280 #define TR_ALARM_RELATIVE 2
281 #define TR_ALARM_RANGE_LOW 1
282 #define TR_ALARM_RANGE_HIGH 2
284 #define TR_PRIORITY_HIGH 0
285 #define TR_PRIORITY_NORMAL 1
286 #define TR_PRIORITY_LOW 2
287 #define TR_PRIORITY_RANGE_LOW 0
288 #define TR_PRIORITY_RANGE_HIGH 2
290 #define TR_STATUS_NOT_STARTED 0
291 #define TR_STATUS_IN_PROGRESS 1
292 #define TR_STATUS_COMPLETED 2
293 #define TR_STATUS_WAITING 3
294 #define TR_STATUS_DEFERRED 4
295 #define TR_STATUS_RANGE_LOW 0
296 #define TR_STATUS_RANGE_HIGH 4
299 // Phone Call Logs record: field constants
302 #define CLL_DIRECTION_RECEIVER 0
303 #define CLL_DIRECTION_EMITTER 1
304 #define CLL_DIRECTION_FAILED 2
305 #define CLL_DIRECTION_MISSING 3
306 #define CLL_DIRECTION_RANGE_LOW 0
307 #define CLL_DIRECTION_RANGE_HIGH 3
309 #define CLL_PHONETYPE_UNDEFINED 0
310 #define CLL_PHONETYPE_OFFICE 1
311 #define CLL_PHONETYPE_HOME 2
312 #define CLL_PHONETYPE_MOBILE 3
313 #define CLL_PHONETYPE_RANGE_LOW 0
314 #define CLL_PHONETYPE_RANGE_HIGH 3
317 // Folder record: field constants
320 #define FR_TYPE_SUBTREE 0x00
321 #define FR_TYPE_DELETED 0x01
322 #define FR_TYPE_INBOX 0x02
323 #define FR_TYPE_OUTBOX 0x03
324 #define FR_TYPE_SENT 0x04
325 #define FR_TYPE_OTHER 0x05
326 #define FR_TYPE_DRAFT 0x0a
328 #define FR_STATUS_ORPHAN 0x50
329 #define FR_STATUS_UNFILED 0x51
330 #define FR_STATUS_FILED 0x52
333 ///////////////////////////////////////////////////////////////////////////////
334 // Packed field structures - odd format used with Service Book records
336 struct PackedField_02
342 } __attribute__ ((packed
));
343 #define PACKED_FIELD_02_HEADER_SIZE (sizeof(Barry::Protocol::PackedField_02) - 1)
345 struct PackedField_10
350 } __attribute__ ((packed
));
351 #define PACKED_FIELD_10_HEADER_SIZE (sizeof(Barry::Protocol::PackedField_10) - 1)
356 ///////////////////////////////////////////////////////////////////////////////
357 // Service Book field and record structures
359 struct ServiceBookConfigField
363 } __attribute__ ((packed
));
364 #define SERVICE_BOOK_CONFIG_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::ServiceBookConfigField) - 1)
367 ///////////////////////////////////////////////////////////////////////////////
368 // DB Command Parameter structures
372 uint16_t recordIndex
; // index comes from RecordStateTable
374 } __attribute__ ((packed
));
375 #define DBC_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBC_Record) - 1)
377 struct DBC_RecordFlags
382 } __attribute__ ((packed
));
383 #define DBC_RECORD_FLAGS_SIZE (sizeof(Barry::Protocol::DBC_RecordFlags))
385 struct DBC_TaggedUpload
387 uint8_t rectype
; // it is unknown exactly what
388 // this field does, but it
389 // shows up here and in the
390 // RecordStateTable, and
391 // for some of the records
392 // they must match when writing
396 } __attribute__ ((packed
));
397 #define DBC_TAGGED_UPLOAD_HEADER_SIZE (sizeof(Barry::Protocol::DBC_TaggedUpload) - 1)
399 struct DBC_IndexedUpload
401 uint8_t unknown
; // observed: 00 or 05
404 } __attribute__ ((packed
));
405 #define DBC_INDEXED_UPLOAD_HEADER_SIZE (sizeof(Barry::Protocol::DBC_IndexedUpload) - 1)
407 struct PasswordChallenge
409 uint8_t remaining_tries
; // number of password attempts
410 // the device will accept before
411 // committing suicide...
412 // starts at 10 and counts down
413 // on each bad password
414 uint8_t unknown
; // observed as 0... probably just
415 // the top byte of a uint16
416 // remaining_tries, but I don't
417 // want to take that chance
418 uint16_t param
; // seems to be a secondary command
419 // of some kind, observed as 0x14
420 // or 0x04, but purpose unknown
421 // possibly a send/receive flag
427 } __attribute__ ((packed
)) u
;
429 } __attribute__ ((packed
));
430 #define PASSWORD_CHALLENGE_HEADER_SIZE (sizeof(Barry::Protocol::PasswordChallenge) - sizeof(Barry::Protocol::PasswordChallenge::Hash))
431 #define PASSWORD_CHALLENGE_SEED_SIZE (PASSWORD_CHALLENGE_HEADER_SIZE + sizeof(uint32_t))
432 #define PASSWORD_CHALLENGE_SIZE (sizeof(Barry::Protocol::PasswordChallenge))
434 struct AttributeFetch
438 uint8_t raw
[1]; // used only in response
439 } __attribute__ ((packed
));
440 #define ATTRIBUTE_FETCH_COMMAND_SIZE (sizeof(Barry::Protocol::AttributeFetch) - 1)
448 } __attribute__ ((packed
)) response
;
449 } __attribute__ ((packed
));
453 uint64_t ticks
; // number of microseconds since
454 // host system startup
455 } __attribute__ ((packed
));
456 #define ECHO_COMMAND_SIZE (sizeof(Barry::Protocol::Echo))
459 ///////////////////////////////////////////////////////////////////////////////
460 // Protocol command structures
465 uint8_t sequence
; // incremented on each socket 0
466 // communication, replies return
467 // the same number from command
472 PasswordChallenge password
;
473 AttributeFetch fetch
;
478 } __attribute__ ((packed
)) u
;
479 } __attribute__ ((packed
));
480 #define SOCKET_COMMAND_HEADER_SIZE (sizeof(Barry::Protocol::SocketCommand) - sizeof(Barry::Protocol::SocketCommand::PacketData))
482 struct SequenceCommand
488 } __attribute__ ((packed
));
492 uint8_t operation
; // see below
493 uint16_t databaseId
; // value from the Database Database
499 DBC_RecordFlags flags
;
500 DBC_TaggedUpload tag_upload
;
501 DBC_IndexedUpload index_upload
;
504 } __attribute__ ((packed
)) u
;
505 } __attribute__ ((packed
));
506 #define DB_COMMAND_HEADER_SIZE (sizeof(Barry::Protocol::DBCommand) - sizeof(Barry::Protocol::DBCommand::Parameters))
510 ///////////////////////////////////////////////////////////////////////////////
511 // Protocol response parameter structures
513 struct DBR_OldDBDBRecord
515 uint16_t count
; // number of fields in record
516 OldDBDBField field
[1];
517 } __attribute__ ((packed
));
518 #define OLD_DBDB_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBR_OldDBDBRecord) - sizeof(Barry::Protocol::OldDBDBField))
520 struct DBR_DBDBRecord
525 } __attribute__ ((packed
));
526 #define DBDB_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBR_DBDBRecord) - sizeof(Barry::Protocol::DBDBField))
528 // Records with a uniqueId. This covers the following records:
530 // Old Contact records
531 // Old Service Book records
532 // Old Calendar records
534 struct DBR_OldTaggedRecord
543 CommonField field
[1];
544 } __attribute__ ((packed
)) u
;
545 } __attribute__ ((packed
));
546 #define DBR_OLD_TAGGED_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBR_OldTaggedRecord) - sizeof(Barry::Protocol::DBR_OldTaggedRecord::TaggedData))
550 uint8_t field1
; // always 'j'
551 uint32_t field2
; // always 0x00000000
552 uint32_t flags
; // flags
553 uint32_t field4
; // normal email and pin recv this is 0x7ff
554 // changes on sent and reply to 0x01ffffff
555 // and 0x003fffff on pin send
556 uint32_t field5
; // always 0x00000000
557 uint32_t field6
; // always 0x00000000
558 uint32_t field7
; // always 0x00000000
559 uint32_t field8
; // always 0x00000000
560 uint16_t field9
; // always 0x0000
562 uint16_t dateReceived
; // the first two of these time fields are always the same
563 uint16_t timeReceived
; //
564 uint16_t dateDuplicate
; // On mail sent from the BB all three fields are identical
565 uint16_t timeDuplicate
; // (time sent)
569 uint16_t priority
; // priority field
570 uint32_t field14
; // always 0x00000000
571 uint32_t field15
; // always 0x00000000
572 uint16_t field16
; // always 0x0000
573 uint32_t field13
; // PIN reply 0x00000000 other time 0xffffffff or 0xfffffffe
574 uint16_t messageSize
; // Message size, 0x0000 if Reply or Saved, 0xffff if below ????
575 uint32_t field18
; // 0x0's and 0xF'x
576 uint32_t field19
; // 0x0's and 0xF's
577 uint16_t field20
; // always 0x0000
578 uint16_t field21
; // 0x01 unless PIN reply then 0x00
579 uint32_t inReplyTo
; // reply to message?
580 uint32_t field22
; // always 0x00000000
581 uint16_t field23
; // FIXME
583 uint32_t folderOne
; // these are the 'folders' the message is in
584 uint32_t folderTwo
; //
586 uint16_t replyMessageFlags
; // 0xfffe on recvd messages
591 uint16_t field27
; // set to 0x00000004 on PIN reply, 0x00000005 otherwise
592 uint32_t headerUID
; // yet another copy of the UID (RecId)
594 uint32_t field29
; // always 0x00000000
595 uint16_t field30
; // always 0x0002
596 uint16_t field31
; // always 0x00000000
597 uint16_t field32
; // always 0x0004
598 uint16_t field34
; // always 0x0000
599 uint8_t field33
; // always 'd'
600 uint32_t timeBlock
; // FIXME
601 CommonField field
[1];
602 } __attribute__ ((packed
));
603 #define MESSAGE_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::MessageRecord) - sizeof(Barry::Protocol::CommonField))
607 ///////////////////////////////////////////////////////////////////////////////
608 // Protocol response structures
617 DBR_OldTaggedRecord tagged
;
618 DBR_OldDBDBRecord old_dbdb
;
621 } __attribute__ ((packed
)) u
;
623 } __attribute__ ((packed
));
624 #define DB_RESPONSE_HEADER_SIZE (sizeof(Barry::Protocol::DBResponse) - sizeof(Barry::Protocol::DBResponse::Parameters))
628 ///////////////////////////////////////////////////////////////////////////////
629 // Database access command structure
631 // even fragmented packets have a tableCmd
640 CommandTableField table
[1];
644 } __attribute__ ((packed
)) u
;
645 } __attribute__ ((packed
));
646 #define SB_DBACCESS_HEADER_SIZE (sizeof(Barry::Protocol::DBAccess) - sizeof(Barry::Protocol::DBAccess::DBData))
647 #define SB_DBACCESS_RETURN_CODE_SIZE (1)
651 ///////////////////////////////////////////////////////////////////////////////
652 // Javaloader protocol structure
658 uint16_t filename_size
;
660 // the rest of the packet is variable length
661 // another string for version, then:
662 // uint32_t cod_size;
664 } __attribute__ ((packed
));
665 #define SB_JLDIRENTRY_HEADER_SIZE (sizeof(Barry::Protocol::JLDirEntry) - 1)
670 uint8_t unknown
; // nearly always 0, might be top half of command
672 } __attribute__ ((packed
));
673 #define SB_JLCOMMAND_HEADER_SIZE (sizeof(Barry::Protocol::JLCommand))
680 } __attribute__ ((packed
));
681 #define SB_JLRESPONSE_HEADER_SIZE (sizeof(Barry::Protocol::JLResponse))
693 } __attribute__ ((packed
));
694 #define SB_JLSCREENINFO_SIZE (sizeof(Barry::Protocol::JLScreenInfo))
696 struct JLEventlogEntry
699 // remainder of packet is variable
700 // it contains the log data as an ASCII (UTF-8?) string
701 } __attribute__ ((packed
));
702 #define SB_JLEVENTLOG_ENTRY_HEADER_SIZE (sizeof(Barry::Protocol::JLEventlogEntry))
706 uint32_t hardware_id
;
712 uint32_t active_wafs
;
713 // older devices (such as 7130) don't this extra data in the
714 // device info packet and will therefore fail the size check
716 } __attribute__ ((packed
));
717 #define SB_JLDEVICEINFO_SIZE (sizeof(Barry::Protocol::JLDeviceInfo))
722 uint16_t size
; // total size of data packet
728 JLScreenInfo screeninfo
;
729 JLEventlogEntry logentry
;
730 JLDeviceInfo devinfo
;
736 } __attribute__ ((packed
)) u
;
738 } __attribute__ ((packed
));
739 #define SB_JLPACKET_HEADER_SIZE (sizeof(Barry::Protocol::JLPacket) - sizeof(Barry::Protocol::JLPacket::PacketData))
742 ///////////////////////////////////////////////////////////////////////////////
743 // JavaDebug protocol structures
750 struct PacketEventRequestSet
{
752 uint8_t suspendPolicy
;
754 } __attribute__ ((packed
));
757 struct PacketEventRequest
{
758 union PacketEventRequestData
{
759 PacketEventRequestSet set
;
760 } __attribute__ ((packed
)) u
;
761 } __attribute__ ((packed
));
764 struct PacketCommand
{
768 union PacketCommandData
{
769 PacketEventRequest eventRequest
;
770 } __attribute__ ((packed
)) u
;
771 } __attribute__ ((packed
));
772 #define JDWP_COMMAND_HEADER_SIZE (sizeof(Barry::Protocol::JDWP::PacketCommand))
778 struct PacketVirtualMachineIDSizes
{
779 uint32_t fieldIDSize
;
780 uint32_t methodIDSize
;
781 uint32_t objectIDSize
;
782 uint32_t referenceTypeIDSize
;
783 uint32_t frameIDSize
;
784 } __attribute__ ((packed
));
786 #define JDWP_PACKETVIRTUALMACHINEIDSIZES_DATA_SIZE sizeof(Barry::Protocol::JDWP::PacketVirtualMachineIDSizes)
789 struct PacketVirtualMachine
{
790 union PacketVirtualMachineData
{
791 PacketVirtualMachineIDSizes IDSizes
;
792 } __attribute__ ((packed
)) u
;
793 } __attribute__ ((packed
));
796 struct PacketResponse
{
799 union PacketResponseData
{
800 PacketVirtualMachine virtualMachine
;
803 } __attribute__ ((packed
)) u
;
804 } __attribute__ ((packed
));
805 #define JDWP_RESPONSE_HEADER_SIZE (sizeof(Barry::Protocol::JDWP::PacketResponse) - sizeof(Barry::Protocol::JDWP::PacketResponse::PacketResponseData))
817 PacketCommand command
;
818 PacketResponse response
;
819 } __attribute__ ((packed
)) u
;
820 } __attribute__ ((packed
));
821 #define JDWP_PACKET_HEADER_SIZE (sizeof(Barry::Protocol::JDWP::Packet) - sizeof(Barry::Protocol::JDWP::Packet::PacketType))
824 #define MAKE_JDWPPACKET(var, data) const Barry::Protocol::JDWP::Packet *var = (const Barry::Protocol::JDWP::Packet *) (data).GetData()
825 #define MAKE_JDWPPACKETPTR_BUF(var, ptr) Barry::Protocol::JDWP::Packet *var = (Barry::Protocol::JDWP::Packet *)ptr
835 } __attribute__ ((packed
)) u
;
836 } __attribute__ ((packed
));
837 #define JDWP_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::JDWField) - sizeof(Barry::Protocol::JDWField::JDWFieldData))
844 } __attribute__ ((packed
));
845 #define SB_JVMCOMMAND_HEADER_SIZE (sizeof(Barry::Protocol::JVMCommand))
852 } __attribute__ ((packed
));
853 #define SB_JVMRESPONSE_HEADER_SIZE (sizeof(Barry::Protocol::JVMResponse))
855 struct JVMModulesList
858 // remainder of packet is variable
859 // it contains the modules list
860 } __attribute__ ((packed
));
861 #define SB_JVMMODULES_LIST_HEADER_SIZE (sizeof(Barry::Protocol::JVMModulesList))
863 struct JVMModulesEntry
868 // remainder of packet is variable
869 // it contains the module name
870 } __attribute__ ((packed
));
871 #define SB_JVMMODULES_ENTRY_HEADER_SIZE (sizeof(Barry::Protocol::JVMModulesEntry))
873 struct JVMThreadsList
876 // remainder of packet is variable
877 // it contains the threads list
878 } __attribute__ ((packed
));
879 #define SB_JVMTHREADS_LIST_HEADER_SIZE (sizeof(Barry::Protocol::JVMThreadsList))
885 } __attribute__ ((packed
));
886 #define SB_JVMUNKNOWN01_HEADER_SIZE (sizeof(Barry::Protocol::JVMUnknown01))
892 } __attribute__ ((packed
));
893 #define SB_JVMUNKNOWN02_HEADER_SIZE (sizeof(Barry::Protocol::JVMUnknown02))
898 uint16_t size
; // total size of data packet
903 JVMResponse response
;
904 JVMModulesList moduleslist
;
905 JVMThreadsList threadslist
;
906 JVMUnknown01 unknown01
;
907 JVMUnknown02 unknown02
;
914 } __attribute__ ((packed
)) u
;
916 } __attribute__ ((packed
));
917 #define SB_JVMPACKET_HEADER_SIZE (sizeof(Barry::Protocol::JVMPacket) - sizeof(Barry::Protocol::JVMPacket::PacketData))
920 ///////////////////////////////////////////////////////////////////////////////
921 // Main packet struct
925 uint16_t socket
; // socket ID... 0 exists by default
926 uint16_t size
; // total size of data packet
932 SocketCommand socket
;
933 SequenceCommand sequence
;
937 } __attribute__ ((packed
)) u
;
938 } __attribute__ ((packed
));
939 #define SB_PACKET_HEADER_SIZE (sizeof(Barry::Protocol::Packet) - sizeof(Barry::Protocol::Packet::PacketData))
941 // WARNING : For JavaLoader we have some packet with 5 size !
942 #define MIN_PACKET_SIZE 5
943 #define MIN_PACKET_DATA_SIZE 4
947 #define MAX_PACKET_SIZE 0x400 // anything beyond this needs to be fragmented
948 #define MAX_PACKET_DATA_SIZE 0x7FC // for data packet (JavaLoader)
950 /////////////////////////////////////////////////////////////////////////////
952 // various useful sizes
955 #define SB_PACKET_DBACCESS_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SB_DBACCESS_HEADER_SIZE)
956 #define SB_FRAG_HEADER_SIZE SB_PACKET_DBACCESS_HEADER_SIZE
958 #define SB_PACKET_COMMAND_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_COMMAND_HEADER_SIZE)
959 #define SB_PACKET_RESPONSE_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_RESPONSE_HEADER_SIZE)
961 #define SB_PACKET_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + DBDB_RECORD_HEADER_SIZE)
962 #define SB_PACKET_OLD_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + OLD_DBDB_RECORD_HEADER_SIZE)
964 #define SB_PACKET_UPLOAD_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + UPLOAD_HEADER_SIZE)
966 #define SB_SEQUENCE_PACKET_SIZE (SB_PACKET_HEADER_SIZE + sizeof(Barry::Protocol::SequenceCommand))
967 #define SB_SOCKET_PACKET_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SOCKET_COMMAND_HEADER_SIZE)
968 #define SB_MODE_PACKET_COMMAND_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(Barry::Protocol::ModeSelect) - sizeof(Barry::Protocol::ModeSelect::ResponseBlock))
969 #define SB_MODE_PACKET_RESPONSE_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(Barry::Protocol::ModeSelect))
973 #define COMMAND(data) (((const Barry::Protocol::Packet *)data.GetData())->command)
974 #define IS_COMMAND(data, cmd) (COMMAND(data) == cmd)
975 #define MAKE_PACKET(var, data) const Barry::Protocol::Packet *var = (const Barry::Protocol::Packet *) (data).GetData()
976 #define MAKE_JLPACKET(var, data) const Barry::Protocol::JLPacket *var = (const Barry::Protocol::JLPacket *) (data).GetData()
977 #define MAKE_JVMPACKET(var, data) const Barry::Protocol::JVMPacket *var = (const Barry::Protocol::JVMPacket *) (data).GetData()
978 #define MAKE_PACKETPTR_BUF(var, ptr) Barry::Protocol::Packet *var = (Barry::Protocol::Packet *)ptr
979 #define MAKE_JLPACKETPTR_BUF(var, ptr) Barry::Protocol::JLPacket *var = (Barry::Protocol::JLPacket *)ptr
980 #define MAKE_JVMPACKETPTR_BUF(var, ptr) Barry::Protocol::JVMPacket *var = (Barry::Protocol::JVMPacket *)ptr
981 #define MAKE_RECORD(type,var,data,off) type *var = (type *) ((data).GetData() + (off))
982 #define MAKE_RECORD_PTR(type,var,data,off) type *var = (type *) ((data) + (off))
984 // fragmentation protocol
985 // send DATA first, then keep sending DATA packets, FRAGMENTing
986 // as required until finished, then send DONE. Both sides behave
987 // this way, so different sized data can be sent in both
990 // the fragmented piece only has a the param header, and then continues
991 // right on with the data
995 // checks packet size and throws BError if not right
996 void CheckSize(const Barry::Data
&packet
, size_t requiredsize
);
997 unsigned int GetSize(const Barry::Data
&packet
);
999 }} // namespace Barry::Protocol