Fixed bug resulting in sibling modules to be ignored in save
[barry.git] / src / protostructs.h
blob5c1454c9349cc46c0633a2caed4a0ee4cb3a4d50
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-2009, 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));
68 ///////////////////////////////////////////////////////////////////////////////
69 // Record Field Formats
71 struct CommonField
73 uint16_t size; // including null terminator
74 uint8_t type;
76 union CommonFieldData
79 GroupLink link;
80 MessageAddress addr;
81 uint32_t uint32;
82 int32_t min1900;
83 uint16_t code;
84 uint8_t raw[1];
85 int16_t int16;
87 } __attribute__ ((packed)) u;
89 } __attribute__ ((packed));
90 #define COMMON_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::CommonField) - sizeof(Barry::Protocol::CommonField::CommonFieldData))
91 #define COMMON_FIELD_MIN1900_SIZE (sizeof(int32_t))
93 struct CommandTableField
95 uint8_t size; // no null terminator
96 uint8_t code;
97 uint8_t name[1];
98 } __attribute__ ((packed));
99 #define COMMAND_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::CommandTableField) - 1)
101 struct OldDBDBField
103 uint16_t dbNumber;
104 uint8_t unknown1;
105 uint32_t dbSize; // assumed from Cassis docs...
106 // always 0 in USB
107 uint16_t dbRecordCount;
108 uint16_t unknown2;
109 uint16_t nameSize; // includes null terminator
110 uint8_t name[1];
111 } __attribute__ ((packed));
112 #define OLD_DBDB_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::OldDBDBField) - 1)
114 struct DBDBField
116 uint16_t dbNumber;
117 uint8_t unknown1;
118 uint32_t dbSize; // assumed from Cassis docs...
119 // always 0 in USB
120 uint32_t dbRecordCount;
121 uint16_t unknown2;
122 uint16_t nameSize; // includes null terminator
123 uint8_t unknown3;
124 uint8_t name[1]; // followed by 2 zeros!
125 uint16_t unknown; // this comes after the
126 // null terminated name, but
127 // is here for size calcs
128 } __attribute__ ((packed));
129 #define DBDB_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::DBDBField) - 1)
131 struct RecordStateTableField
133 uint8_t rectype; // it is unknown exactly what
134 // this field does, but it
135 // shows up here and in the
136 // tagged record header, and
137 // for some of the records
138 // they must match when writing
139 uint16_t index;
140 uint32_t uniqueId; // matches the uniqueId of say,
141 // address book records
142 uint8_t flags; // bit 0x01 is the dirty flag
143 // don't know if any other bits
144 // are used
145 #define BARRY_RSTF_DIRTY 0x01
146 uint8_t unknown2[4];
147 } __attribute__ ((packed));
149 struct CalendarRecurrenceDataField // as documented in the Cassis project spec
151 uint8_t type;
152 #define CRDF_TYPE_DAY 0x01
153 #define CRDF_TYPE_MONTH_BY_DATE 0x03
154 #define CRDF_TYPE_MONTH_BY_DAY 0x04
155 #define CRDF_TYPE_YEAR_BY_DATE 0x05
156 #define CRDF_TYPE_YEAR_BY_DAY 0x06
157 #define CRDF_TYPE_WEEK 0x0c
159 uint8_t unknown; // always 0x01
160 uint16_t interval;
161 uint32_t startTime;
162 uint32_t endTime; // 0xFFFFFFFF for never
164 union Additional
166 // Note: blank fields should be set to 0
168 struct Day
170 uint8_t day[6]; // always zeros!
171 } __attribute__ ((packed)) day;
173 struct MonthByDate
175 uint8_t monthDay; // day of month to recur on
176 // (1-31)
177 uint8_t blank[5];
178 } __attribute__ ((packed)) month_by_date;
180 struct MonthByDay
182 uint8_t weekDay; // day of week to recur on (0-6)
183 uint8_t week; // week of month to recur on
184 // (1 to 5, first week, second
185 // week, etc)
186 uint8_t blank[4];
187 } __attribute__ ((packed)) month_by_day;
189 struct YearByDate
191 uint8_t monthDay; // day of month to recur on
192 // (1-31)
193 uint8_t blank;
194 uint8_t month; // month to recur on (1-12)
195 uint8_t blank_[3];
196 } __attribute__ ((packed)) year_by_date;
198 struct YearByDay
200 uint8_t weekDay; // day of week to recur on (0-6)
201 uint8_t week; // week of month (1 to 5)
202 uint8_t month; // (1-12)
203 uint8_t blank[3];
204 } __attribute__ ((packed)) year_by_day;
206 struct Week
208 uint8_t days; // bitmask
209 #define CRDF_WD_SUN 0x01
210 #define CRDF_WD_MON 0x02
211 #define CRDF_WD_TUE 0x04
212 #define CRDF_WD_WED 0x08
213 #define CRDF_WD_THU 0x10
214 #define CRDF_WD_FRI 0x20
215 #define CRDF_WD_SAT 0x40
217 uint8_t blank[5];
218 } __attribute__ ((packed)) week;
220 } __attribute__ ((packed)) u;
222 } __attribute__ ((packed));
223 #define CALENDAR_RECURRENCE_DATA_FIELD_SIZE sizeof(Barry::Protocol::CalendarRecurrenceDataField)
226 // Calendar record: field constants
229 #define CR_FREEBUSY_FREE 0
230 #define CR_FREEBUSY_TENTATIVE 1
231 #define CR_FREEBUSY_BUSY 2
232 #define CR_FREEBUSY_OUT_OF_OFFICE 3
233 #define CR_FREEBUSY_RANGE_LOW 0
234 #define CR_FREEBUSY_RANGE_HIGH 3
236 #define CR_CLASS_PUBLIC 0
237 #define CR_CLASS_CONFIDENTIAL 1
238 #define CR_CLASS_PRIVATE 2
239 #define CR_CLASS_RANGE_LOW 0
240 #define CR_CLASS_RANGE_HIGH 2
244 // Task record: field constants
247 #define TR_ALARM_DATE 1
248 #define TR_ALARM_RELATIVE 2
249 #define TR_ALARM_RANGE_LOW 1
250 #define TR_ALARM_RANGE_HIGH 2
252 #define TR_PRIORITY_HIGH 0
253 #define TR_PRIORITY_NORMAL 1
254 #define TR_PRIORITY_LOW 2
255 #define TR_PRIORITY_RANGE_LOW 0
256 #define TR_PRIORITY_RANGE_HIGH 2
258 #define TR_STATUS_NOT_STARTED 0
259 #define TR_STATUS_IN_PROGRESS 1
260 #define TR_STATUS_COMPLETED 2
261 #define TR_STATUS_WAITING 3
262 #define TR_STATUS_DEFERRED 4
263 #define TR_STATUS_RANGE_LOW 0
264 #define TR_STATUS_RANGE_HIGH 4
268 // Folder record: field constants
271 #define FR_TYPE_SUBTREE 0x00
272 #define FR_TYPE_DELETED 0x01
273 #define FR_TYPE_INBOX 0x02
274 #define FR_TYPE_OUTBOX 0x03
275 #define FR_TYPE_SENT 0x04
276 #define FR_TYPE_OTHER 0x05
277 #define FR_TYPE_DRAFT 0x0a
279 #define FR_STATUS_ORPHAN 0x50
280 #define FR_STATUS_UNFILED 0x51
281 #define FR_STATUS_FILED 0x52
284 ///////////////////////////////////////////////////////////////////////////////
285 // Packed field structures - odd format used with Service Book records
287 struct PackedField_02
289 uint8_t code;
290 uint8_t size;
291 uint8_t type;
292 uint8_t raw[1];
293 } __attribute__ ((packed));
294 #define PACKED_FIELD_02_HEADER_SIZE (sizeof(Barry::Protocol::PackedField_02) - 1)
296 struct PackedField_10
298 uint8_t type;
299 uint8_t size;
300 uint8_t raw[1];
301 } __attribute__ ((packed));
302 #define PACKED_FIELD_10_HEADER_SIZE (sizeof(Barry::Protocol::PackedField_10) - 1)
307 ///////////////////////////////////////////////////////////////////////////////
308 // Service Book field and record structures
310 struct ServiceBookConfigField
312 uint8_t format;
313 uint8_t fields[1];
314 } __attribute__ ((packed));
315 #define SERVICE_BOOK_CONFIG_FIELD_HEADER_SIZE (sizeof(Barry::Protocol::ServiceBookConfigField) - 1)
318 ///////////////////////////////////////////////////////////////////////////////
319 // DB Command Parameter structures
321 struct DBC_Record
323 uint16_t recordIndex; // index comes from RecordStateTable
324 uint8_t data[1];
325 } __attribute__ ((packed));
326 #define DBC_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBC_Record) - 1)
328 struct DBC_RecordFlags
330 uint8_t unknown;
331 uint16_t index;
332 uint8_t unknown2[5];
333 } __attribute__ ((packed));
334 #define DBC_RECORD_FLAGS_SIZE (sizeof(Barry::Protocol::DBC_RecordFlags))
336 struct DBC_TaggedUpload
338 uint8_t rectype; // it is unknown exactly what
339 // this field does, but it
340 // shows up here and in the
341 // RecordStateTable, and
342 // for some of the records
343 // they must match when writing
344 uint32_t uniqueId;
345 uint8_t unknown2;
346 uint8_t data[1];
347 } __attribute__ ((packed));
348 #define DBC_TAGGED_UPLOAD_HEADER_SIZE (sizeof(Barry::Protocol::DBC_TaggedUpload) - 1)
350 struct DBC_IndexedUpload
352 uint8_t unknown; // observed: 00 or 05
353 uint16_t index;
354 uint8_t data[1];
355 } __attribute__ ((packed));
356 #define DBC_INDEXED_UPLOAD_HEADER_SIZE (sizeof(Barry::Protocol::DBC_IndexedUpload) - 1)
358 struct PasswordChallenge
360 uint8_t remaining_tries; // number of password attempts
361 // the device will accept before
362 // committing suicide...
363 // starts at 10 and counts down
364 // on each bad password
365 uint8_t unknown; // observed as 0... probably just
366 // the top byte of a uint16
367 // remaining_tries, but I don't
368 // want to take that chance
369 uint16_t param; // seems to be a secondary command
370 // of some kind, observed as 0x14
371 // or 0x04, but purpose unknown
372 // possibly a send/receive flag
373 // bit (0x10/0x00)
374 union Hash
376 uint32_t seed;
377 uint8_t hash[20];
378 } __attribute__ ((packed)) u;
380 } __attribute__ ((packed));
381 #define PASSWORD_CHALLENGE_HEADER_SIZE (sizeof(Barry::Protocol::PasswordChallenge) - sizeof(Barry::Protocol::PasswordChallenge::Hash))
382 #define PASSWORD_CHALLENGE_SEED_SIZE (PASSWORD_CHALLENGE_HEADER_SIZE + sizeof(uint32_t))
383 #define PASSWORD_CHALLENGE_SIZE (sizeof(Barry::Protocol::PasswordChallenge))
385 struct AttributeFetch
387 uint16_t object;
388 uint16_t attribute;
389 uint8_t raw[1]; // used only in response
390 } __attribute__ ((packed));
391 #define ATTRIBUTE_FETCH_COMMAND_SIZE (sizeof(Barry::Protocol::AttributeFetch) - 1)
393 struct ModeSelect
395 uint8_t name[16];
396 struct ResponseBlock
398 uint8_t unknown[20];
399 } __attribute__ ((packed)) response;
400 } __attribute__ ((packed));
403 ///////////////////////////////////////////////////////////////////////////////
404 // Protocol command structures
406 struct SocketCommand
408 uint16_t socket;
409 uint8_t sequence; // incremented on each socket 0
410 // communication, replies return
411 // the same number from command
413 union PacketData
416 PasswordChallenge password;
417 AttributeFetch fetch;
418 ModeSelect mode;
419 uint8_t raw[1];
421 } __attribute__ ((packed)) u;
422 } __attribute__ ((packed));
423 #define SOCKET_COMMAND_HEADER_SIZE (sizeof(Barry::Protocol::SocketCommand) - sizeof(Barry::Protocol::SocketCommand::PacketData))
425 struct SequenceCommand
427 uint8_t unknown1;
428 uint8_t unknown2;
429 uint8_t unknown3;
430 uint32_t sequenceId;
431 } __attribute__ ((packed));
433 struct DBCommand
435 uint8_t operation; // see below
436 uint16_t databaseId; // value from the Database Database
438 union Parameters
441 DBC_Record record;
442 DBC_RecordFlags flags;
443 DBC_TaggedUpload tag_upload;
444 DBC_IndexedUpload index_upload;
445 uint8_t raw[1];
447 } __attribute__ ((packed)) u;
448 } __attribute__ ((packed));
449 #define DB_COMMAND_HEADER_SIZE (sizeof(Barry::Protocol::DBCommand) - sizeof(Barry::Protocol::DBCommand::Parameters))
453 ///////////////////////////////////////////////////////////////////////////////
454 // Protocol response parameter structures
456 struct DBR_OldDBDBRecord
458 uint16_t count; // number of fields in record
459 OldDBDBField field[1];
460 } __attribute__ ((packed));
461 #define OLD_DBDB_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBR_OldDBDBRecord) - sizeof(Barry::Protocol::OldDBDBField))
463 struct DBR_DBDBRecord
465 uint16_t count;
466 uint8_t unknown[3];
467 DBDBField field[1];
468 } __attribute__ ((packed));
469 #define DBDB_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBR_DBDBRecord) - sizeof(Barry::Protocol::DBDBField))
471 // Records with a uniqueId. This covers the following records:
473 // Old Contact records
474 // Old Service Book records
475 // Old Calendar records
477 struct DBR_OldTaggedRecord
479 uint8_t rectype;
480 uint16_t index;
481 uint32_t uniqueId;
482 uint8_t unknown2;
484 union TaggedData
486 CommonField field[1];
487 } __attribute__ ((packed)) u;
488 } __attribute__ ((packed));
489 #define DBR_OLD_TAGGED_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::DBR_OldTaggedRecord) - sizeof(Barry::Protocol::DBR_OldTaggedRecord::TaggedData))
491 struct MessageRecord
493 uint8_t field1; // always 'j'
494 uint32_t field2; // always 0x00000000
495 uint32_t flags; // flags
496 uint32_t field4; // normal email and pin recv this is 0x7ff
497 // changes on sent and reply to 0x01ffffff
498 // and 0x003fffff on pin send
499 uint32_t field5; // always 0x00000000
500 uint32_t field6; // always 0x00000000
501 uint32_t field7; // always 0x00000000
502 uint32_t field8; // always 0x00000000
503 uint16_t field9; // always 0x0000
505 uint16_t dateReceived; // the first two of these time fields are always the same
506 uint16_t timeReceived; //
507 uint16_t dateDuplicate; // On mail sent from the BB all three fields are identical
508 uint16_t timeDuplicate; // (time sent)
509 uint16_t dateSent;
510 uint16_t timeSent;
512 uint16_t priority; // priority field
513 uint32_t field14; // always 0x00000000
514 uint32_t field15; // always 0x00000000
515 uint16_t field16; // always 0x0000
516 uint32_t field13; // PIN reply 0x00000000 other time 0xffffffff or 0xfffffffe
517 uint16_t messageSize; // Message size, 0x0000 if Reply or Saved, 0xffff if below ????
518 uint32_t field18; // 0x0's and 0xF'x
519 uint32_t field19; // 0x0's and 0xF's
520 uint16_t field20; // always 0x0000
521 uint16_t field21; // 0x01 unless PIN reply then 0x00
522 uint32_t inReplyTo; // reply to message?
523 uint32_t field22; // always 0x00000000
524 uint16_t field23; // FIXME
526 uint32_t folderOne; // these are the 'folders' the message is in
527 uint32_t folderTwo; //
529 uint16_t replyMessageFlags; // 0xfffe on recvd messages
530 // 0x001b on reply
531 // 0x0015 on send
532 // 0x3 pin send
533 // 0x2 on pin recv
534 uint16_t field27; // set to 0x00000004 on PIN reply, 0x00000005 otherwise
535 uint32_t headerUID; // yet another copy of the UID (RecId)
537 uint32_t field29; // always 0x00000000
538 uint16_t field30; // always 0x0002
539 uint16_t field31; // always 0x00000000
540 uint16_t field32; // always 0x0004
541 uint16_t field34; // always 0x0000
542 uint8_t field33; // always 'd'
543 uint32_t timeBlock; // FIXME
544 CommonField field[1];
545 } __attribute__ ((packed));
546 #define MESSAGE_RECORD_HEADER_SIZE (sizeof(Barry::Protocol::MessageRecord) - sizeof(Barry::Protocol::CommonField))
550 ///////////////////////////////////////////////////////////////////////////////
551 // Protocol response structures
553 struct DBResponse
555 uint8_t operation;
557 union Parameters
560 DBR_OldTaggedRecord tagged;
561 DBR_OldDBDBRecord old_dbdb;
562 DBR_DBDBRecord dbdb;
564 } __attribute__ ((packed)) u;
566 } __attribute__ ((packed));
567 #define DB_RESPONSE_HEADER_SIZE (sizeof(Barry::Protocol::DBResponse) - sizeof(Barry::Protocol::DBResponse::Parameters))
571 ///////////////////////////////////////////////////////////////////////////////
572 // Database access command structure
574 // even fragmented packets have a tableCmd
575 struct DBAccess
577 uint8_t tableCmd;
579 union DBData
581 DBCommand command;
582 DBResponse response;
583 CommandTableField table[1];
584 uint8_t return_code;
585 uint8_t fragment[1];
587 } __attribute__ ((packed)) u;
588 } __attribute__ ((packed));
589 #define SB_DBACCESS_HEADER_SIZE (sizeof(Barry::Protocol::DBAccess) - sizeof(Barry::Protocol::DBAccess::DBData))
590 #define SB_DBACCESS_RETURN_CODE_SIZE (1)
594 ///////////////////////////////////////////////////////////////////////////////
595 // Javaloader protocol structure
597 struct JLDirEntry
599 uint16_t unknown;
600 uint32_t timestamp;
601 uint16_t filename_size;
602 uint8_t filename[1];
603 // the rest of the packet is variable length
604 // another string for version, then:
605 // uint32_t cod_size;
607 } __attribute__ ((packed));
608 #define SB_JLDIRENTRY_HEADER_SIZE (sizeof(Barry::Protocol::JLDirEntry) - 1)
610 struct JLCommand
612 uint8_t command;
613 uint8_t unknown; // nearly always 0, might be top half of command
614 uint16_t size;
615 } __attribute__ ((packed));
616 #define SB_JLCOMMAND_HEADER_SIZE (sizeof(Barry::Protocol::JLCommand))
618 struct JLResponse
620 uint8_t command;
621 uint8_t unknown;
622 uint16_t expect;
623 } __attribute__ ((packed));
624 #define SB_JLRESPONSE_HEADER_SIZE (sizeof(Barry::Protocol::JLResponse))
626 struct JLScreenInfo
628 uint16_t unknown1;
629 uint16_t unknown2;
630 uint16_t unknown3;
631 uint16_t width;
632 uint16_t height;
633 uint16_t unknown4;
634 uint16_t unknown5;
635 uint16_t unknown6;
636 } __attribute__ ((packed));
637 #define SB_JLSCREENINFO_SIZE (sizeof(Barry::Protocol::JLScreenInfo))
639 struct JLEventlogEntry
641 uint16_t size;
642 // remainder of packet is variable
643 // it contains the log data as an ASCII (UTF-8?) string
644 } __attribute__ ((packed));
645 #define SB_JLEVENTLOG_ENTRY_HEADER_SIZE (sizeof(Barry::Protocol::JLEventlogEntry))
647 struct JLPacket
649 uint16_t socket;
650 uint16_t size; // total size of data packet
652 union PacketData
654 JLCommand command;
655 JLResponse response;
656 JLScreenInfo screeninfo;
657 JLEventlogEntry logentry;
658 uint8_t raw[1];
659 char filename[1];
660 uint32_t cod_size;
661 uint32_t timestamp;
662 uint16_t id;
663 } __attribute__ ((packed)) u;
665 } __attribute__ ((packed));
666 #define SB_JLPACKET_HEADER_SIZE (sizeof(Barry::Protocol::JLPacket) - sizeof(Barry::Protocol::JLPacket::PacketData))
668 ///////////////////////////////////////////////////////////////////////////////
669 // Main packet struct
671 struct Packet
673 uint16_t socket; // socket ID... 0 exists by default
674 uint16_t size; // total size of data packet
675 uint8_t command;
677 union PacketData
680 SocketCommand socket;
681 SequenceCommand sequence;
682 DBAccess db;
683 uint8_t raw[1];
685 } __attribute__ ((packed)) u;
686 } __attribute__ ((packed));
687 #define SB_PACKET_HEADER_SIZE (sizeof(Barry::Protocol::Packet) - sizeof(Barry::Protocol::Packet::PacketData))
689 // WARNING : For JavaLoader we have some packet with 5 size !
690 #define MIN_PACKET_SIZE 5
691 #define MIN_PACKET_DATA_SIZE 4
694 // maximum sizes
695 #define MAX_PACKET_SIZE 0x400 // anything beyond this needs to be fragmented
696 #define MAX_PACKET_DATA_SIZE 0x7FF // for data packet (JavaLoader)
698 /////////////////////////////////////////////////////////////////////////////
700 // various useful sizes
703 #define SB_PACKET_DBACCESS_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SB_DBACCESS_HEADER_SIZE)
704 #define SB_FRAG_HEADER_SIZE SB_PACKET_DBACCESS_HEADER_SIZE
706 #define SB_PACKET_COMMAND_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_COMMAND_HEADER_SIZE)
707 #define SB_PACKET_RESPONSE_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + DB_RESPONSE_HEADER_SIZE)
709 #define SB_PACKET_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + DBDB_RECORD_HEADER_SIZE)
710 #define SB_PACKET_OLD_DBDB_HEADER_SIZE (SB_PACKET_RESPONSE_HEADER_SIZE + OLD_DBDB_RECORD_HEADER_SIZE)
712 #define SB_PACKET_UPLOAD_HEADER_SIZE (SB_PACKET_DBACCESS_HEADER_SIZE + UPLOAD_HEADER_SIZE)
714 #define SB_SEQUENCE_PACKET_SIZE (SB_PACKET_HEADER_SIZE + sizeof(Barry::Protocol::SequenceCommand))
715 #define SB_SOCKET_PACKET_HEADER_SIZE (SB_PACKET_HEADER_SIZE + SOCKET_COMMAND_HEADER_SIZE)
716 #define SB_MODE_PACKET_COMMAND_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(Barry::Protocol::ModeSelect) - sizeof(Barry::Protocol::ModeSelect::ResponseBlock))
717 #define SB_MODE_PACKET_RESPONSE_SIZE (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(Barry::Protocol::ModeSelect))
720 // Macros
721 #define COMMAND(data) (((const Barry::Protocol::Packet *)data.GetData())->command)
722 #define IS_COMMAND(data, cmd) (COMMAND(data) == cmd)
723 #define MAKE_PACKET(var, data) const Barry::Protocol::Packet *var = (const Barry::Protocol::Packet *) (data).GetData()
724 #define MAKE_JLPACKET(var, data) const Barry::Protocol::JLPacket *var = (const Barry::Protocol::JLPacket *) (data).GetData()
725 #define MAKE_PACKETPTR_BUF(var, ptr) Barry::Protocol::Packet *var = (Barry::Protocol::Packet *)ptr
726 #define MAKE_JLPACKETPTR_BUF(var, ptr) Barry::Protocol::JLPacket *var = (Barry::Protocol::JLPacket *)ptr
727 #define MAKE_RECORD(type,var,data,off) type *var = (type *) ((data).GetData() + (off))
728 #define MAKE_RECORD_PTR(type,var,data,off) type *var = (type *) ((data) + (off))
730 // fragmentation protocol
731 // send DATA first, then keep sending DATA packets, FRAGMENTing
732 // as required until finished, then send DONE. Both sides behave
733 // this way, so different sized data can be sent in both
734 // directions
736 // the fragmented piece only has a the param header, and then continues
737 // right on with the data
741 // checks packet size and throws BError if not right
742 void CheckSize(const Barry::Data &packet, size_t requiredsize);
743 unsigned int GetSize(const Barry::Data &packet);
745 }} // namespace Barry::Protocol
747 #endif