Debian Codegraph @

src/boot.h

raw symbols SCIP
1 // Copyright (C) 2014 Sacha Refshauge
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 3.0.
6
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 3.0 for more details.
11
12 // A copy of the GPL 3.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14
15 // Official GIT repository and contact information can be found at
16 // http://github.com/xsacha/Sachesi
17
18 #pragma once
19
20 #include <QObject>
21 #include <QFile>
22 #include <QTimer>
23 #include <QThread>
24 #include <QStringList>
25 #include <libusb-1.0/libusb.h>
26
27 #define BLACKBERRY_VENDOR_ID 0x0FCA
28
29 #define BUFFER_SIZE 2048
30
31 #ifdef _WIN32
32 #pragma pack(push,1)
33 #endif
34 // message with type 00
35 typedef struct ControlMessageHeader {
36 unsigned short type; // 0000
37 unsigned short packetSize;
38 unsigned char command;
39 unsigned char mode;
40 unsigned short packetId;
41 // any data specific to the message is added after
42 }
43 #ifndef _WIN32
44 __attribute__((packed)) ControlMessageHeader;
45 #else
46 ControlMessageHeader;
47 #pragma pack(pop)
48 #endif
49
50 enum SachesiCommand {
51 commandInfo = 0x01,
52 commandBootloader = 0x02,
53 commandNuke = 0x03,
54 commandDebug = 0x04
55 };
56
57 enum ControlMessageCommand {
58 kCommandPing = 0x01, // OUT
59 kCommandPingResponse = 0x02, // IN
60 kCommandReboot = 0x03, // OUT
61 kCommandRebootResponse = 0x04, // IN
62 kCommandGetVariable = 0x05, // OUT
63 kCommandGetVariableResponse = 0x06, // IN
64 kCommandSetMode = 0x07, // OUT
65 kCommandSetModeSuccess = 0x08, // IN
66 kCommandSetModeFailure = 0x09, // IN
67 kCommandGetPasswordInfo = 0x0A, // OUT
68 kCommandLoadTransferredData = 0x0B, // IN/OUT
69 kCommandLoadTransferredDataSuccess = 0x0C, // IN/OUT
70 kCommandLoadTransferredDataFailure = 0x0D, // IN/OUT
71 kCommandGetPasswordInfoResponse = 0x0E, // IN
72 kCommandSendPassword = 0x0F, // OUT
73 kCommandSendPasswordCorrect = 0x10, // IN
74 kCommandUnkn1 = 0x11, // ?
75 kCommandUnkn1Response = 0x12, // OUT
76 kCommandReadyForDataTransfer = 0x13 // IN
77 };
78
79 typedef enum BootloaderMode {
80 // value = mode entry in message 00 struct when mode is set
81 kBootloaderRimReinit = 0x0,
82 kBootloaderRimBoot = 0x1,
83 kBootloaderRamBoot = 0x2,
84 kBootloaderUPL = 0x3,
85
86 // Modes with no 'Mode Entry'
87 kBootloaderRimBootNuke = 0x4 // Wipe User partition
88 } BootloaderMode;
89
90 class Boot : public QThread
91 {
92 Q_OBJECT
93 Q_PROPERTY(bool connecting READ connecting WRITE setConnecting NOTIFY connectingChanged)
94 Q_PROPERTY(int command READ command WRITE setCommand NOTIFY commandChanged)
95 Q_PROPERTY(QStringList devices MEMBER _devices NOTIFY devicesChanged)
96 public:
97 Boot();
98 ~Boot();
99 libusb_device_handle* openDevice(libusb_device* dev);
100 int closeDevice(libusb_device_handle* handle);
101 int sendControlMessage(libusb_device_handle* aHandle, uint8_t aCommand, QByteArray* aData, int aDataSize);
102 int receiveControlMessage(libusb_device_handle* aHandle, ControlMessageHeader* aHeader, QByteArray* aData);
103 void commandReboot(libusb_device_handle* aHandle);
104 void commandPing(libusb_device_handle* aHandle);
105 bool commandSendPass(libusb_device_handle* aHandle);
106 void commandSendLoader(libusb_device_handle* aHandle);
107 int commandGetVariable(libusb_device_handle* aHandle, int variable, QByteArray* buffer, int bufferSize);
108 void commandSetMode(libusb_device_handle* aHandle, BootloaderMode mode);
109 void commandLoadBootloader(libusb_device_handle* aHandle);
110 void commandTransferData(libusb_device_handle* aHandle);
111
112 bool connecting() const;
113 int command() const;
114 void setCommand(const int &command);
115 void setConnecting(const bool &connecting);
116 signals:
117 void connectingChanged();
118 void commandChanged();
119 void devicesChanged();
120 public slots:
121 Q_INVOKABLE void search();
122 Q_INVOKABLE void connect();
123 Q_INVOKABLE void disconnect();
124 Q_INVOKABLE void setCommandMode(int mode, bool rebootAfter);
125 void newPassword(QString newPass);
126 void exit() {
127 _kill = true;
128 }
129 private:
130 int _bootloaderMode;
131 bool _connecting;
132 int _command;
133 bool _rebootAfter;
134 short _packetNum;
135 int _found;
136 QString _password;
137 QStringList _devices;
138 QList<QByteArray*> bootloaderModeData;
139 bool _kill;
140 };