protostructs.h

Go to the documentation of this file.
00001 ///
00002 /// \file       protostructs.h
00003 ///             USB Blackberry bulk protocol API.  This is split out from
00004 ///             protocol.h so that low level, packed structs can be
00005 ///             compiled separately from the application.  This prevents
00006 ///             aliasing problems in the application, or using
00007 ///             -fno-strict-aliasing, which the library only needs.
00008 ///
00009 ///             Do not include this in any Barry library header.
00010 ///             This may only be included from .cc files, in order
00011 ///             to hide aliasing concernes from the application.
00012 ///
00013 
00014 /*
00015     Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
00016 
00017     This program is free software; you can redistribute it and/or modify
00018     it under the terms of the GNU General Public License as published by
00019     the Free Software Foundation; either version 2 of the License, or
00020     (at your option) any later version.
00021 
00022     This program is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00025 
00026     See the GNU General Public License in the COPYING file at the
00027     root directory of this project for more details.
00028 */
00029 
00030 #ifndef __BARRY_PROTOSTRUCTS_H__
00031 #define __BARRY_PROTOSTRUCTS_H__
00032 
00033 #include <stdint.h>
00034 #include <sys/types.h>
00035 
00036 // forward declarations
00037 namespace Barry { class Data; }
00038 
00039 namespace Barry { namespace Protocol {
00040 
00041 ///////////////////////////////////////////////////////////////////////////////
00042 union SizePacket
00043 {
00044         uint16_t size;
00045         char buffer[4];
00046 } __attribute__ ((packed));
00047 
00048 
00049 ///////////////////////////////////////////////////////////////////////////////
00050 // Record sub-field structs
00051 
00052 struct GroupLink                                // used for Contacts records
00053 {
00054         uint32_t        uniqueId;
00055         uint16_t        unknown;
00056 } __attribute__ ((packed));
00057 
00058 struct MessageAddress                           // used for Message records
00059 {
00060         uint8_t         unknown[8];
00061         uint8_t         addr[1];        // 2 null terminated strings: first
00062                                         // contains full name, second contains
00063                                         // the email address
00064 } __attribute__ ((packed));
00065 
00066 
00067 ///////////////////////////////////////////////////////////////////////////////
00068 // SMS Message field and record structures
00069 
00070 struct SMSMetaData
00071 {
00072         uint8_t         recv; // if received, this is set to 1; otherwise 0
00073         uint8_t         flags;
00074 #define SMS_FLG_NEW_CONVERSATION 0x20
00075 #define SMS_FLG_SAVED 0x10
00076 #define SMS_FLG_DELETED 0x08
00077 #define SMS_FLG_OPENED 0x01
00078 
00079         uint8_t         new_flag;
00080         uint16_t        zero; // constantly 0
00081         uint32_t        status;
00082 #define SMS_STA_RECEIVED 0x000007ff
00083 #define SMS_STA_DRAFT 0x7fffffff
00084 
00085         uint32_t        error_id;
00086         uint64_t        timestamp;
00087         uint64_t        service_center_timestamp;
00088         uint8_t         dcs;
00089 #define SMS_DCS_7BIT 0x00
00090 #define SMS_DCS_8BIT 0x01
00091 #define SMS_DCS_UCS2 0x02
00092 
00093 } __attribute__ ((packed));
00094 #define SMS_METADATA_SIZE       (sizeof(::Barry::Protocol::SMSMetaData))
00095 
00096 
00097 
00098 ///////////////////////////////////////////////////////////////////////////////
00099 // Record Field Formats
00100 
00101 struct CommonField
00102 {
00103         uint16_t        size;                   // including null terminator
00104         uint8_t         type;
00105 
00106         union CommonFieldData
00107         {
00108 
00109                 GroupLink       link;
00110                 MessageAddress  addr;
00111                 SMSMetaData     sms_metadata;
00112                 uint64_t        timestamp;
00113                 uint64_t        uint64;
00114                 uint32_t        uint32;
00115                 int32_t         min1900;
00116                 uint16_t        code;
00117                 uint8_t         raw[1];
00118                 int16_t         int16;
00119 
00120         } __attribute__ ((packed)) u;
00121 
00122 } __attribute__ ((packed));
00123 #define COMMON_FIELD_HEADER_SIZE        (sizeof(::Barry::Protocol::CommonField) - sizeof(::Barry::Protocol::CommonField::CommonFieldData))
00124 #define COMMON_FIELD_MIN1900_SIZE       (sizeof(int32_t))
00125 
00126 struct CommandTableField
00127 {
00128         uint8_t         size;           // no null terminator
00129         uint8_t         code;
00130         uint8_t         name[1];
00131 } __attribute__ ((packed));
00132 #define COMMAND_FIELD_HEADER_SIZE       (sizeof(::Barry::Protocol::CommandTableField) - 1)
00133 
00134 struct OldDBDBField
00135 {
00136         uint16_t        dbNumber;
00137         uint8_t         unknown1;
00138         uint32_t        dbSize;                 // assumed from Cassis docs...
00139                                                 // always 0 in USB
00140         uint16_t        dbRecordCount;
00141         uint16_t        unknown2;
00142         uint16_t        nameSize;               // includes null terminator
00143         uint8_t         name[1];
00144 } __attribute__ ((packed));
00145 #define OLD_DBDB_FIELD_HEADER_SIZE      (sizeof(::Barry::Protocol::OldDBDBField) - 1)
00146 
00147 struct DBDBField
00148 {
00149         uint16_t        dbNumber;
00150         uint8_t         unknown1;
00151         uint32_t        dbSize;                 // assumed from Cassis docs...
00152                                                 // always 0 in USB
00153         uint32_t        dbRecordCount;
00154         uint16_t        unknown2;
00155         uint16_t        nameSize;               // includes null terminator
00156         uint8_t         unknown3;
00157         uint8_t         name[1];                // followed by 2 zeros!
00158         uint16_t        unknown;                // this comes after the
00159                                                 // null terminated name, but
00160                                                 // is here for size calcs
00161 } __attribute__ ((packed));
00162 #define DBDB_FIELD_HEADER_SIZE  (sizeof(::Barry::Protocol::DBDBField) - 1)
00163 
00164 struct RecordStateTableField
00165 {
00166         uint8_t         rectype;                // it is unknown exactly what
00167                                                 // this field does, but it
00168                                                 // shows up here and in the
00169                                                 // tagged record header, and
00170                                                 // for some of the records
00171                                                 // they must match when writing
00172         uint16_t        index;
00173         uint32_t        uniqueId;               // matches the uniqueId of say,
00174                                                 // address book records
00175         uint8_t         flags;                  // bit 0x01 is the dirty flag
00176                                                 // don't know if any other bits
00177                                                 // are used
00178 #define BARRY_RSTF_DIRTY        0x01
00179         uint8_t         unknown2[4];
00180 } __attribute__ ((packed));
00181 
00182 struct CalendarRecurrenceDataField  // as documented in the Cassis project spec
00183 {
00184         uint8_t         type;
00185 #define CRDF_TYPE_DAY           0x01
00186 #define CRDF_TYPE_MONTH_BY_DATE 0x03
00187 #define CRDF_TYPE_MONTH_BY_DAY  0x04
00188 #define CRDF_TYPE_YEAR_BY_DATE  0x05
00189 #define CRDF_TYPE_YEAR_BY_DAY   0x06
00190 #define CRDF_TYPE_WEEK          0x0c
00191 
00192         uint8_t         unknown;                // always 0x01
00193         uint16_t        interval;
00194         uint32_t        startTime;
00195         uint32_t        endTime;                // 0xFFFFFFFF for never
00196 
00197         union Additional
00198         {
00199                 // Note: blank fields should be set to 0
00200 
00201                 struct Day
00202                 {
00203                         uint8_t day[6];         // always zeros!
00204                 } __attribute__ ((packed)) day;
00205 
00206                 struct MonthByDate
00207                 {
00208                         uint8_t monthDay;       // day of month to recur on
00209                                                 // (1-31)
00210                         uint8_t blank[5];
00211                 } __attribute__ ((packed)) month_by_date;
00212 
00213                 struct MonthByDay
00214                 {
00215                         uint8_t weekDay;        // day of week to recur on (0-6)
00216                         uint8_t week;           // week of month to recur on
00217                                                 // (1 to 5, first week, second
00218                                                 // week, etc)
00219                         uint8_t blank[4];
00220                 } __attribute__ ((packed)) month_by_day;
00221 
00222                 struct YearByDate
00223                 {
00224                         uint8_t monthDay;       // day of month to recur on
00225                                                 // (1-31)
00226                         uint8_t blank;
00227                         uint8_t month;          // month to recur on (1-12)
00228                         uint8_t blank_[3];
00229                 } __attribute__ ((packed)) year_by_date;
00230 
00231                 struct YearByDay
00232                 {
00233                         uint8_t weekDay;        // day of week to recur on (0-6)
00234                         uint8_t week;           // week of month (1 to 5)
00235                         uint8_t month;          // (1-12)
00236                         uint8_t blank[3];
00237                 } __attribute__ ((packed)) year_by_day;
00238 
00239                 struct Week
00240                 {
00241                         uint8_t days;           // bitmask
00242                         #define CRDF_WD_SUN     0x01
00243                         #define CRDF_WD_MON     0x02
00244                         #define CRDF_WD_TUE     0x04
00245                         #define CRDF_WD_WED     0x08
00246                         #define CRDF_WD_THU     0x10
00247                         #define CRDF_WD_FRI     0x20
00248                         #define CRDF_WD_SAT     0x40
00249 
00250                         uint8_t blank[5];
00251                 } __attribute__ ((packed)) week;
00252 
00253         } __attribute__ ((packed)) u;
00254 
00255 } __attribute__ ((packed));
00256 #define CALENDAR_RECURRENCE_DATA_FIELD_SIZE     sizeof(::Barry::Protocol::CalendarRecurrenceDataField)
00257 
00258 //
00259 // Calendar record: field constants
00260 //
00261 
00262 #define CR_FREEBUSY_FREE                0
00263 #define CR_FREEBUSY_TENTATIVE           1
00264 #define CR_FREEBUSY_BUSY                2
00265 #define CR_FREEBUSY_OUT_OF_OFFICE       3
00266 #define CR_FREEBUSY_RANGE_LOW           0
00267 #define CR_FREEBUSY_RANGE_HIGH          3
00268 
00269 #define CR_CLASS_PUBLIC                 0
00270 #define CR_CLASS_CONFIDENTIAL           1
00271 #define CR_CLASS_PRIVATE                2
00272 #define CR_CLASS_RANGE_LOW              0
00273 #define CR_CLASS_RANGE_HIGH             2
00274 
00275 
00276 //
00277 // Task record: field constants
00278 //
00279 
00280 #define TR_ALARM_DATE                   1
00281 #define TR_ALARM_RELATIVE               2
00282 #define TR_ALARM_RANGE_LOW              1
00283 #define TR_ALARM_RANGE_HIGH             2
00284 
00285 #define TR_PRIORITY_HIGH                0
00286 #define TR_PRIORITY_NORMAL              1
00287 #define TR_PRIORITY_LOW                 2
00288 #define TR_PRIORITY_RANGE_LOW           0
00289 #define TR_PRIORITY_RANGE_HIGH          2
00290 
00291 #define TR_STATUS_NOT_STARTED           0
00292 #define TR_STATUS_IN_PROGRESS           1
00293 #define TR_STATUS_COMPLETED             2
00294 #define TR_STATUS_WAITING               3
00295 #define TR_STATUS_DEFERRED              4
00296 #define TR_STATUS_RANGE_LOW             0
00297 #define TR_STATUS_RANGE_HIGH            4
00298 
00299 //
00300 // Phone Call Logs record: field constants
00301 //
00302 //
00303 #define CLL_DIRECTION_RECEIVER          0
00304 #define CLL_DIRECTION_EMITTER           1
00305 #define CLL_DIRECTION_FAILED            2
00306 #define CLL_DIRECTION_MISSING           3
00307 #define CLL_DIRECTION_RANGE_LOW         0
00308 #define CLL_DIRECTION_RANGE_HIGH        3
00309 
00310 #define CLL_PHONETYPE_UNDEFINED         0
00311 #define CLL_PHONETYPE_OFFICE            1
00312 #define CLL_PHONETYPE_HOME                      2
00313 #define CLL_PHONETYPE_MOBILE            3
00314 #define CLL_PHONETYPE_RANGE_LOW         0
00315 #define CLL_PHONETYPE_RANGE_HIGH        3
00316 
00317 //
00318 // Folder record: field constants
00319 //
00320 
00321 #define FR_TYPE_SUBTREE                 0x00
00322 #define FR_TYPE_DELETED                 0x01
00323 #define FR_TYPE_INBOX                   0x02
00324 #define FR_TYPE_OUTBOX                  0x03
00325 #define FR_TYPE_SENT                    0x04
00326 #define FR_TYPE_OTHER                   0x05
00327 #define FR_TYPE_DRAFT                   0x0a
00328 
00329 #define FR_STATUS_ORPHAN                0x50
00330 #define FR_STATUS_UNFILED               0x51
00331 #define FR_STATUS_FILED                 0x52
00332 
00333 
00334 ///////////////////////////////////////////////////////////////////////////////
00335 // Packed field structures - odd format used with Service Book records
00336 
00337 struct PackedField_02
00338 {
00339         uint8_t         code;
00340         uint8_t         size;
00341         uint8_t         type;
00342         uint8_t         raw[1];
00343 } __attribute__ ((packed));
00344 #define PACKED_FIELD_02_HEADER_SIZE     (sizeof(::Barry::Protocol::PackedField_02) - 1)
00345 
00346 struct PackedField_10
00347 {
00348         uint8_t         type;
00349         uint8_t         size;
00350         uint8_t         raw[1];
00351 } __attribute__ ((packed));
00352 #define PACKED_FIELD_10_HEADER_SIZE     (sizeof(::Barry::Protocol::PackedField_10) - 1)
00353 
00354 
00355 
00356 
00357 ///////////////////////////////////////////////////////////////////////////////
00358 // Service Book field and record structures
00359 
00360 struct ServiceBookConfigField
00361 {
00362         uint8_t         format;
00363         uint8_t         fields[1];
00364 } __attribute__ ((packed));
00365 #define SERVICE_BOOK_CONFIG_FIELD_HEADER_SIZE (sizeof(::Barry::Protocol::ServiceBookConfigField) - 1)
00366 
00367 
00368 ///////////////////////////////////////////////////////////////////////////////
00369 // DB Command Parameter structures
00370 
00371 struct DBC_Record
00372 {
00373         uint16_t        recordIndex;    // index comes from RecordStateTable
00374         uint8_t         data[1];
00375 } __attribute__ ((packed));
00376 #define DBC_RECORD_HEADER_SIZE          (sizeof(::Barry::Protocol::DBC_Record) - 1)
00377 
00378 struct DBC_RecordFlags
00379 {
00380         uint8_t         unknown;
00381         uint16_t        index;
00382         uint8_t         unknown2[5];
00383 } __attribute__ ((packed));
00384 #define DBC_RECORD_FLAGS_SIZE           (sizeof(::Barry::Protocol::DBC_RecordFlags))
00385 
00386 struct DBC_TaggedUpload
00387 {
00388         uint8_t         rectype;                // it is unknown exactly what
00389                                                 // this field does, but it
00390                                                 // shows up here and in the
00391                                                 // RecordStateTable, and
00392                                                 // for some of the records
00393                                                 // they must match when writing
00394         uint32_t        uniqueId;
00395         uint8_t         unknown2;
00396         uint8_t         data[1];
00397 } __attribute__ ((packed));
00398 #define DBC_TAGGED_UPLOAD_HEADER_SIZE   (sizeof(::Barry::Protocol::DBC_TaggedUpload) - 1)
00399 
00400 struct DBC_IndexedUpload
00401 {
00402         uint8_t         unknown;        // observed: 00 or 05
00403         uint16_t        index;
00404         uint8_t         data[1];
00405 } __attribute__ ((packed));
00406 #define DBC_INDEXED_UPLOAD_HEADER_SIZE  (sizeof(::Barry::Protocol::DBC_IndexedUpload) - 1)
00407 
00408 struct PasswordChallenge
00409 {
00410         uint8_t         remaining_tries;        // number of password attempts
00411                                                 // the device will accept before
00412                                                 // committing suicide...
00413                                                 // starts at 10 and counts down
00414                                                 // on each bad password
00415         uint8_t         unknown;                // observed as 0... probably just
00416                                                 // the top byte of a uint16
00417                                                 // remaining_tries, but I don't
00418                                                 // want to take that chance
00419         uint16_t        param;                  // seems to be a secondary command
00420                                                 // of some kind, observed as 0x14
00421                                                 // or 0x04, but purpose unknown
00422                                                 // possibly a send/receive flag
00423                                                 // bit (0x10/0x00)
00424         union Hash
00425         {
00426                 uint32_t        seed;
00427                 uint8_t         hash[20];
00428         } __attribute__ ((packed)) u;
00429 
00430 } __attribute__ ((packed));
00431 #define PASSWORD_CHALLENGE_HEADER_SIZE  (sizeof(::Barry::Protocol::PasswordChallenge) - sizeof(::Barry::Protocol::PasswordChallenge::Hash))
00432 #define PASSWORD_CHALLENGE_SEED_SIZE    (PASSWORD_CHALLENGE_HEADER_SIZE + sizeof(uint32_t))
00433 #define PASSWORD_CHALLENGE_SIZE         (sizeof(::Barry::Protocol::PasswordChallenge))
00434 
00435 struct AttributeFetch
00436 {
00437         uint16_t        object;
00438         uint16_t        attribute;
00439         uint8_t         raw[1];                 // used only in response
00440 } __attribute__ ((packed));
00441 #define ATTRIBUTE_FETCH_COMMAND_SIZE    (sizeof(::Barry::Protocol::AttributeFetch) - 1)
00442 
00443 struct ModeSelect
00444 {
00445         uint8_t         name[16];
00446         struct ResponseBlock
00447         {
00448                 uint8_t         unknown[20];
00449         } __attribute__ ((packed)) response;
00450 } __attribute__ ((packed));
00451 
00452 struct Echo
00453 {
00454         uint64_t        ticks;                  // number of microseconds since
00455                                                 // host system startup
00456 } __attribute__ ((packed));
00457 #define ECHO_COMMAND_SIZE               (sizeof(::Barry::Protocol::Echo))
00458 
00459 
00460 ///////////////////////////////////////////////////////////////////////////////
00461 // Protocol command structures
00462 
00463 struct SocketCommand
00464 {
00465         uint16_t        socket;
00466         uint8_t         sequence;               // incremented on each socket 0
00467                                                 // communication, replies return
00468                                                 // the same number from command
00469 
00470         union PacketData
00471         {
00472 
00473                 PasswordChallenge       password;
00474                 AttributeFetch          fetch;
00475                 ModeSelect              mode;
00476                 uint8_t                 raw[1];
00477                 Echo                    echo;
00478 
00479         } __attribute__ ((packed)) u;
00480 } __attribute__ ((packed));
00481 #define SOCKET_COMMAND_HEADER_SIZE              (sizeof(::Barry::Protocol::SocketCommand) - sizeof(::Barry::Protocol::SocketCommand::PacketData))
00482 
00483 struct SequenceCommand
00484 {
00485         uint8_t         unknown1;
00486         uint8_t         unknown2;
00487         uint8_t         unknown3;
00488         uint32_t        sequenceId;
00489 } __attribute__ ((packed));
00490 
00491 struct DBCommand
00492 {
00493         uint8_t         operation;      // see below
00494         uint16_t        databaseId;     // value from the Database Database
00495 
00496         union Parameters
00497         {
00498 
00499                 DBC_Record              record;
00500                 DBC_RecordFlags         flags;
00501                 DBC_TaggedUpload        tag_upload;
00502                 DBC_IndexedUpload       index_upload;
00503                 uint8_t                 raw[1];
00504 
00505         } __attribute__ ((packed)) u;
00506 } __attribute__ ((packed));
00507 #define DB_COMMAND_HEADER_SIZE          (sizeof(::Barry::Protocol::DBCommand) - sizeof(::Barry::Protocol::DBCommand::Parameters))
00508 
00509 
00510 
00511 ///////////////////////////////////////////////////////////////////////////////
00512 // Protocol response parameter structures
00513 
00514 struct DBR_OldDBDBRecord
00515 {
00516         uint16_t        count;                  // number of fields in record
00517         OldDBDBField    field[1];
00518 } __attribute__ ((packed));
00519 #define OLD_DBDB_RECORD_HEADER_SIZE     (sizeof(::Barry::Protocol::DBR_OldDBDBRecord) - sizeof(::Barry::Protocol::OldDBDBField))
00520 
00521 struct DBR_DBDBRecord
00522 {
00523         uint16_t        count;
00524         uint8_t         unknown[3];
00525         DBDBField       field[1];
00526 } __attribute__ ((packed));
00527 #define DBDB_RECORD_HEADER_SIZE         (sizeof(::Barry::Protocol::DBR_DBDBRecord) - sizeof(::Barry::Protocol::DBDBField))
00528 
00529 // Records with a uniqueId.  This covers the following records:
00530 //
00531 //      Old Contact records
00532 //      Old Service Book records
00533 //      Old Calendar records
00534 //
00535 struct DBR_OldTaggedRecord
00536 {
00537         uint8_t         rectype;
00538         uint16_t        index;
00539         uint32_t        uniqueId;
00540         uint8_t         unknown2;
00541 
00542         union TaggedData
00543         {
00544                 CommonField     field[1];
00545         } __attribute__ ((packed)) u;
00546 } __attribute__ ((packed));
00547 #define DBR_OLD_TAGGED_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::DBR_OldTaggedRecord) - sizeof(::Barry::Protocol::DBR_OldTaggedRecord::TaggedData))
00548 
00549 struct MessageRecord
00550 {
00551         uint8_t         field1;         // always 'j'
00552         uint32_t        field2;         // always 0x00000000
00553         uint32_t        flags;          // flags
00554         uint32_t        field4;         // normal email and pin recv this is 0x7ff
00555                                         // changes on sent and reply to 0x01ffffff
00556                                         // and 0x003fffff on pin send
00557         uint32_t        field5;         // always 0x00000000
00558         uint32_t        field6;         // always 0x00000000
00559         uint32_t        field7;         // always 0x00000000
00560         uint32_t        field8;         // always 0x00000000
00561         uint16_t        field9;         // always 0x0000
00562 
00563         uint16_t        dateReceived;   // the first two of these time fields are always the same
00564         uint16_t        timeReceived;   //
00565         uint16_t        dateDuplicate;  // On mail sent from the BB all three fields are identical
00566         uint16_t        timeDuplicate;  // (time sent)
00567         uint16_t        dateSent;
00568         uint16_t        timeSent;
00569 
00570         uint16_t        priority;       // priority field
00571         uint32_t        field14;        // always 0x00000000
00572         uint32_t        field15;        // always 0x00000000
00573         uint16_t        field16;        // always 0x0000
00574         uint32_t        field13;        // PIN reply 0x00000000 other time 0xffffffff or 0xfffffffe
00575         uint16_t        messageSize;    // Message size, 0x0000 if Reply or Saved, 0xffff if below ????
00576         uint32_t        field18;        // 0x0's and 0xF'x
00577         uint32_t        field19;        // 0x0's and 0xF's
00578         uint16_t        field20;        // always 0x0000
00579         uint16_t        field21;        // 0x01 unless PIN reply then 0x00
00580         uint32_t        inReplyTo;      // reply to message?
00581         uint32_t        field22;        // always 0x00000000
00582         uint16_t        field23;        // FIXME
00583 
00584         uint32_t        folderOne;      // these are the 'folders' the message is in
00585         uint32_t        folderTwo;      //
00586 
00587         uint16_t        replyMessageFlags;      // 0xfffe on recvd messages
00588                                         // 0x001b on reply
00589                                         // 0x0015 on send
00590                                         // 0x3 pin send
00591                                         // 0x2 on pin recv
00592         uint16_t        field27;        // set to 0x00000004 on PIN reply, 0x00000005 otherwise
00593         uint32_t        headerUID;      // yet another copy of the UID (RecId)
00594 
00595         uint32_t        field29;        // always 0x00000000
00596         uint16_t        field30;        // always 0x0002
00597         uint16_t        field31;        // always 0x00000000
00598         uint16_t        field32;        // always 0x0004
00599         uint16_t        field34;        // always 0x0000
00600         uint8_t         field33;        // always 'd'
00601         uint32_t        timeBlock;      // FIXME
00602         CommonField     field[1];
00603 } __attribute__ ((packed));
00604 #define MESSAGE_RECORD_HEADER_SIZE (sizeof(::Barry::Protocol::MessageRecord) - sizeof(::Barry::Protocol::CommonField))
00605 
00606 
00607 
00608 ///////////////////////////////////////////////////////////////////////////////
00609 // Protocol response structures
00610 
00611 struct DBResponse
00612 {
00613         uint8_t         operation;
00614 
00615         union Parameters
00616         {
00617 
00618                 DBR_OldTaggedRecord     tagged;
00619                 DBR_OldDBDBRecord       old_dbdb;
00620                 DBR_DBDBRecord          dbdb;
00621 
00622         } __attribute__ ((packed)) u;
00623 
00624 } __attribute__ ((packed));
00625 #define DB_RESPONSE_HEADER_SIZE         (sizeof(::Barry::Protocol::DBResponse) - sizeof(::Barry::Protocol::DBResponse::Parameters))
00626 
00627 
00628 
00629 ///////////////////////////////////////////////////////////////////////////////
00630 // Database access command structure
00631 
00632 // even fragmented packets have a tableCmd
00633 struct DBAccess
00634 {
00635         uint8_t         tableCmd;
00636 
00637         union DBData
00638         {
00639                 DBCommand               command;
00640                 DBResponse              response;
00641                 CommandTableField       table[1];
00642                 uint8_t                 return_code;
00643                 uint8_t                 fragment[1];
00644 
00645         } __attribute__ ((packed)) u;
00646 } __attribute__ ((packed));
00647 #define SB_DBACCESS_HEADER_SIZE                 (sizeof(::Barry::Protocol::DBAccess) - sizeof(::Barry::Protocol::DBAccess::DBData))
00648 #define SB_DBACCESS_RETURN_CODE_SIZE            (1)
00649 
00650 
00651 
00652 ///////////////////////////////////////////////////////////////////////////////
00653 // Javaloader protocol structure
00654 
00655 struct JLDirEntry
00656 {
00657         uint16_t        unknown;
00658         uint32_t        timestamp;
00659         uint16_t        filename_size;
00660         uint8_t         filename[1];
00661         // the rest of the packet is variable length
00662         // another string for version, then:
00663         // uint32_t     cod_size;
00664 
00665 } __attribute__ ((packed));
00666 #define SB_JLDIRENTRY_HEADER_SIZE               (sizeof(::Barry::Protocol::JLDirEntry) - 1)
00667 
00668 struct JLCommand
00669 {
00670         uint8_t         command;
00671         uint8_t         unknown;        // nearly always 0, might be top half of command
00672         uint16_t        size;
00673 } __attribute__ ((packed));
00674 #define SB_JLCOMMAND_HEADER_SIZE                (sizeof(::Barry::Protocol::JLCommand))
00675 
00676 struct JLResponse
00677 {
00678         uint8_t         command;
00679         uint8_t         unknown;
00680         uint16_t        expect;
00681 } __attribute__ ((packed));
00682 #define SB_JLRESPONSE_HEADER_SIZE               (sizeof(::Barry::Protocol::JLResponse))
00683 
00684 struct JLScreenInfo
00685 {
00686         uint16_t        unknown1;
00687         uint16_t        unknown2;
00688         uint16_t        unknown3;
00689         uint16_t        width;
00690         uint16_t        height;
00691         uint16_t        unknown4;
00692         uint16_t        unknown5;
00693         uint16_t        unknown6;
00694 } __attribute__ ((packed));
00695 #define SB_JLSCREENINFO_SIZE                    (sizeof(::Barry::Protocol::JLScreenInfo))
00696 
00697 struct JLEventlogEntry
00698 {
00699         uint16_t        size;
00700         // remainder of packet is variable
00701         // it contains the log data as an ASCII (UTF-8?) string
00702 } __attribute__ ((packed));
00703 #define SB_JLEVENTLOG_ENTRY_HEADER_SIZE         (sizeof(::Barry::Protocol::JLEventlogEntry))
00704 
00705 struct JLDeviceInfo
00706 {
00707         uint32_t        hardware_id;
00708         uint32_t        pin;
00709         uint32_t        os_version;
00710         uint32_t        vm_version;
00711         uint32_t        radio_id;
00712         uint32_t        vendor_id;
00713         uint32_t        active_wafs;
00714         // older devices (such as 7130) don't this extra data in the
00715         // device info packet and will therefore fail the size check
00716         //uint8_t               raw[4];
00717 } __attribute__ ((packed));
00718 #define SB_JLDEVICEINFO_SIZE                    (sizeof(::Barry::Protocol::JLDeviceInfo))
00719 
00720 struct JLPacket
00721 {
00722         uint16_t        socket;
00723         uint16_t        size;           // total size of data packet
00724 
00725         union PacketData
00726         {
00727                 JLCommand               command;
00728                 JLResponse              response;
00729                 JLScreenInfo            screeninfo;
00730                 JLEventlogEntry         logentry;
00731                 JLDeviceInfo            devinfo;
00732                 uint8_t                 raw[1];
00733                 char                    filename[1];
00734                 uint32_t                cod_size;
00735                 uint32_t                timestamp;
00736                 uint16_t                id;
00737         } __attribute__ ((packed)) u;
00738 
00739 } __attribute__ ((packed));
00740 #define SB_JLPACKET_HEADER_SIZE         (sizeof(::Barry::Protocol::JLPacket) - sizeof(::Barry::Protocol::JLPacket::PacketData))
00741 
00742 
00743 ///////////////////////////////////////////////////////////////////////////////
00744 // JavaDebug protocol structures
00745 
00746 namespace JDWP {
00747 
00748         // Packet command
00749         //----------------
00750 
00751         struct PacketEventRequestSet {
00752                 uint8_t eventKind;
00753                 uint8_t suspendPolicy;
00754                 uint32_t modifiers;
00755         } __attribute__ ((packed));
00756 
00757 
00758         struct PacketEventRequest {
00759                 union PacketEventRequestData {
00760                         PacketEventRequestSet set;
00761                 } __attribute__ ((packed)) u;
00762         } __attribute__ ((packed));
00763 
00764 
00765         struct PacketCommand {
00766                 uint8_t commandset;
00767                 uint8_t command;
00768 
00769                 union PacketCommandData {
00770                         PacketEventRequest eventRequest;
00771                 } __attribute__ ((packed)) u;
00772         } __attribute__ ((packed));
00773         #define JDWP_COMMAND_HEADER_SIZE                        (sizeof(::Barry::Protocol::JDWP::PacketCommand))
00774 
00775 
00776         // Packet response
00777         //-----------------
00778 
00779         struct PacketVirtualMachineIDSizes {
00780                 uint32_t fieldIDSize;
00781                 uint32_t methodIDSize;
00782                 uint32_t objectIDSize;
00783                 uint32_t referenceTypeIDSize;
00784                 uint32_t frameIDSize;
00785         } __attribute__ ((packed));
00786 
00787         #define JDWP_PACKETVIRTUALMACHINEIDSIZES_DATA_SIZE              sizeof(::Barry::Protocol::JDWP::PacketVirtualMachineIDSizes)
00788 
00789 
00790         struct PacketVirtualMachine {
00791                 union PacketVirtualMachineData {
00792                         PacketVirtualMachineIDSizes IDSizes;
00793                 } __attribute__ ((packed)) u;
00794         } __attribute__ ((packed));
00795 
00796 
00797         struct PacketResponse {
00798                 uint16_t errorcode;
00799 
00800                 union PacketResponseData {
00801                         PacketVirtualMachine virtualMachine;
00802                         uint32_t value;
00803                         uint8_t raw[1];
00804                 } __attribute__ ((packed)) u;
00805         } __attribute__ ((packed));
00806         #define JDWP_RESPONSE_HEADER_SIZE                       (sizeof(::Barry::Protocol::JDWP::PacketResponse) - sizeof(::Barry::Protocol::JDWP::PacketResponse::PacketResponseData))
00807 
00808 
00809         // Generic packet
00810         //----------------
00811 
00812         struct Packet {
00813                 uint32_t length;
00814                 uint32_t id;
00815                 uint8_t flags;
00816 
00817                 union PacketType {
00818                         PacketCommand command;
00819                         PacketResponse response;
00820                 } __attribute__ ((packed)) u;
00821         } __attribute__ ((packed));
00822         #define JDWP_PACKET_HEADER_SIZE                 (sizeof(::Barry::Protocol::JDWP::Packet) - sizeof(::Barry::Protocol::JDWP::Packet::PacketType))
00823 
00824 
00825         #define MAKE_JDWPPACKET(var, data)              const ::Barry::Protocol::JDWP::Packet *var = (const ::Barry::Protocol::JDWP::Packet *) (data).GetData()
00826         #define MAKE_JDWPPACKETPTR_BUF(var, ptr)                ::Barry::Protocol::JDWP::Packet *var = (::Barry::Protocol::JDWP::Packet *)ptr
00827 
00828 
00829 } // namespace JDWP
00830 
00831 struct JDWField {
00832         uint32_t size;
00833 
00834         union JDWFieldData {
00835                 uint8_t raw[1];
00836         } __attribute__ ((packed)) u;
00837 } __attribute__ ((packed));
00838 #define JDWP_FIELD_HEADER_SIZE                  (sizeof(::Barry::Protocol::JDWField) - sizeof(::Barry::Protocol::JDWField::JDWFieldData))
00839 
00840 struct JVMCommand
00841 {
00842         uint16_t        size;
00843         uint8_t         command;
00844         uint8_t         raw[1];
00845 } __attribute__ ((packed));
00846 #define SB_JVMCOMMAND_HEADER_SIZE               (sizeof(::Barry::Protocol::JVMCommand))
00847 
00848 struct JVMResponse
00849 {
00850         uint8_t         command;
00851         uint8_t         unknown;
00852         uint16_t        expect;
00853 } __attribute__ ((packed));
00854 #define SB_JVMRESPONSE_HEADER_SIZE              (sizeof(::Barry::Protocol::JVMResponse))
00855 
00856 struct JVMModulesList
00857 {
00858         uint32_t        nbr;
00859         // remainder of packet is variable
00860         // it contains the modules list 
00861 } __attribute__ ((packed));
00862 #define SB_JVMMODULES_LIST_HEADER_SIZE          (sizeof(::Barry::Protocol::JVMModulesList))
00863 
00864 struct JVMModulesEntry
00865 {
00866         uint32_t        id;
00867         uint32_t        uniqueId;
00868         uint16_t        sizename;
00869         // remainder of packet is variable
00870         // it contains the module name
00871 } __attribute__ ((packed));
00872 #define SB_JVMMODULES_ENTRY_HEADER_SIZE         (sizeof(::Barry::Protocol::JVMModulesEntry))
00873 
00874 struct JVMThreadsList
00875 {
00876         uint32_t        nbr;
00877         // remainder of packet is variable
00878         // it contains the threads list 
00879 } __attribute__ ((packed));
00880 #define SB_JVMTHREADS_LIST_HEADER_SIZE          (sizeof(::Barry::Protocol::JVMThreadsList))
00881 
00882 struct JVMUnknown01
00883 {
00884         uint8_t         byte;
00885         uint32_t        address;
00886 } __attribute__ ((packed));
00887 #define SB_JVMUNKNOWN01_HEADER_SIZE                     (sizeof(::Barry::Protocol::JVMUnknown01))
00888 
00889 struct JVMUnknown02
00890 {
00891         uint32_t        address1;
00892         uint32_t        address2;
00893 } __attribute__ ((packed));
00894 #define SB_JVMUNKNOWN02_HEADER_SIZE                     (sizeof(::Barry::Protocol::JVMUnknown02))
00895 
00896 struct JVMPacket
00897 {
00898         uint16_t        socket;
00899         uint16_t        size;           // total size of data packet
00900 
00901         union PacketData
00902         {
00903                 JVMCommand              command;
00904                 JVMResponse             response;
00905                 JVMModulesList          moduleslist;
00906                 JVMThreadsList          threadslist;
00907                 JVMUnknown01            unknown01;
00908                 JVMUnknown02            unknown02;
00909                 uint32_t                address;
00910                 uint16_t                expect;
00911                 uint16_t                msglength;
00912                 uint16_t                value;
00913                 uint8_t                 status;
00914                 uint8_t                 raw[1];
00915         } __attribute__ ((packed)) u;
00916 
00917 } __attribute__ ((packed));
00918 #define SB_JVMPACKET_HEADER_SIZE                (sizeof(::Barry::Protocol::JVMPacket) - sizeof(::Barry::Protocol::JVMPacket::PacketData))
00919 
00920 
00921 ///////////////////////////////////////////////////////////////////////////////
00922 // Main packet struct
00923 
00924 struct Packet
00925 {
00926         uint16_t        socket;         // socket ID... 0 exists by default
00927         uint16_t        size;           // total size of data packet
00928         uint8_t         command;
00929 
00930         union PacketData
00931         {
00932 
00933                 SocketCommand           socket;
00934                 SequenceCommand         sequence;
00935                 DBAccess                db;
00936                 uint8_t                 raw[1];
00937 
00938         } __attribute__ ((packed)) u;
00939 } __attribute__ ((packed));
00940 #define SB_PACKET_HEADER_SIZE                   (sizeof(::Barry::Protocol::Packet) - sizeof(::Barry::Protocol::Packet::PacketData))
00941 
00942 // WARNING : For JavaLoader we have some packet with 5 size !
00943 #define MIN_PACKET_SIZE                 5
00944 #define MIN_PACKET_DATA_SIZE            4
00945 
00946 
00947 // maximum sizes
00948 #define MAX_PACKET_SIZE                 0x400   // anything beyond this needs to be fragmented
00949 #define MAX_PACKET_DATA_SIZE            0x7FC   // for data packet (JavaLoader)
00950 
00951 /////////////////////////////////////////////////////////////////////////////
00952 //
00953 // various useful sizes
00954 //
00955 
00956 #define SB_PACKET_DBACCESS_HEADER_SIZE          (SB_PACKET_HEADER_SIZE + SB_DBACCESS_HEADER_SIZE)
00957 #define SB_FRAG_HEADER_SIZE                     SB_PACKET_DBACCESS_HEADER_SIZE
00958 
00959 #define SB_PACKET_COMMAND_HEADER_SIZE           (SB_PACKET_DBACCESS_HEADER_SIZE + DB_COMMAND_HEADER_SIZE)
00960 #define SB_PACKET_RESPONSE_HEADER_SIZE          (SB_PACKET_DBACCESS_HEADER_SIZE + DB_RESPONSE_HEADER_SIZE)
00961 
00962 #define SB_PACKET_DBDB_HEADER_SIZE              (SB_PACKET_RESPONSE_HEADER_SIZE + DBDB_RECORD_HEADER_SIZE)
00963 #define SB_PACKET_OLD_DBDB_HEADER_SIZE          (SB_PACKET_RESPONSE_HEADER_SIZE + OLD_DBDB_RECORD_HEADER_SIZE)
00964 
00965 #define SB_PACKET_UPLOAD_HEADER_SIZE            (SB_PACKET_DBACCESS_HEADER_SIZE + UPLOAD_HEADER_SIZE)
00966 
00967 #define SB_SEQUENCE_PACKET_SIZE                 (SB_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::SequenceCommand))
00968 #define SB_SOCKET_PACKET_HEADER_SIZE            (SB_PACKET_HEADER_SIZE + SOCKET_COMMAND_HEADER_SIZE)
00969 #define SB_MODE_PACKET_COMMAND_SIZE             (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::ModeSelect) - sizeof(::Barry::Protocol::ModeSelect::ResponseBlock))
00970 #define SB_MODE_PACKET_RESPONSE_SIZE            (SB_SOCKET_PACKET_HEADER_SIZE + sizeof(::Barry::Protocol::ModeSelect))
00971 
00972 
00973 // Macros
00974 #define COMMAND(data)                           (((const ::Barry::Protocol::Packet *)data.GetData())->command)
00975 #define IS_COMMAND(data, cmd)                   (COMMAND(data) == cmd)
00976 #define MAKE_PACKET(var, data)                  const ::Barry::Protocol::Packet *var = (const ::Barry::Protocol::Packet *) (data).GetData()
00977 #define MAKE_JLPACKET(var, data)                const ::Barry::Protocol::JLPacket *var = (const ::Barry::Protocol::JLPacket *) (data).GetData()
00978 #define MAKE_JVMPACKET(var, data)               const ::Barry::Protocol::JVMPacket *var = (const ::Barry::Protocol::JVMPacket *) (data).GetData()
00979 #define MAKE_PACKETPTR_BUF(var, ptr)            ::Barry::Protocol::Packet *var = (::Barry::Protocol::Packet *)ptr
00980 #define MAKE_JLPACKETPTR_BUF(var, ptr)          ::Barry::Protocol::JLPacket *var = (::Barry::Protocol::JLPacket *)ptr
00981 #define MAKE_JVMPACKETPTR_BUF(var, ptr)         ::Barry::Protocol::JVMPacket *var = (::Barry::Protocol::JVMPacket *)ptr
00982 #define MAKE_RECORD(type,var,data,off)          type *var = (type *) ((data).GetData() + (off))
00983 #define MAKE_RECORD_PTR(type,var,data,off)      type *var = (type *) ((data) + (off))
00984 
00985 // fragmentation protocol
00986 // send DATA first, then keep sending DATA packets, FRAGMENTing
00987 // as required until finished, then send DONE.  Both sides behave
00988 // this way, so different sized data can be sent in both
00989 // directions
00990 //
00991 // the fragmented piece only has a the param header, and then continues
00992 // right on with the data
00993 
00994 
00995 
00996 // checks packet size and throws BError if not right
00997 void CheckSize(const Barry::Data &packet, size_t requiredsize);
00998 unsigned int GetSize(const Barry::Data &packet);
00999 
01000 }} // namespace Barry::Protocol
01001 
01002 #endif
01003 
Generated by  doxygen 1.6.2-20100208