Payout
A thin wrapper around the SSP protocol from ITL
SSPComs.h
1 
2 #ifndef _ITLSSPCOMSH
3 #define _ITLSSPCOMSH
4 #define CCONV _stdcall
5 #define NOMANGLE
6 
7 
8 #include "itl_types.h"
9 #include "ssp_defines.h"
10 
11 #ifdef __cplusplus
12  extern "C" {
13 #endif
14 
15 
16 #define MAX_SSP_PORT 200
17 
18 #define NO_ENCRYPTION 0
19 #define ENCRYPTION_SET 1
20 
21 typedef struct{
22  unsigned long long FixedKey;
23  unsigned long long EncryptKey;
25 
26 
27 typedef struct{
28  unsigned short packetTime;
29  unsigned char PacketLength;
30  unsigned char PacketData[255];
31 }SSP_PACKET;
32 
33 
34 
35 
36 
37 
38 typedef struct{
39  SSP_FULL_KEY Key;
40  unsigned long BaudRate;
41  unsigned long Timeout;
42  unsigned char PortNumber;
43  unsigned char SSPAddress;
44  unsigned char RetryLevel;
45  unsigned char EncryptionStatus;
46  unsigned char CommandDataLength;
47  unsigned char CommandData[255];
48  unsigned char ResponseStatus;
49  unsigned char ResponseDataLength;
50  unsigned char ResponseData[255];
51  unsigned char IgnoreError;
53 
54 
55 typedef struct{
56  unsigned char txData[255];
57  unsigned char txPtr;
58  unsigned char rxData[255];
59  unsigned char rxPtr;
60  unsigned char txBufferLength;
61  unsigned char rxBufferLength;
62  unsigned char SSPAddress;
63  unsigned char NewResponse;
64  unsigned char CheckStuff;
66 
67 
68 
69 typedef struct{
70  long long Generator;
71  long long Modulus;
72  long long HostInter;
73  long long HostRandom;
74  long long SlaveInterKey;
75  long long SlaveRandom;
76  long long KeyHost;
77  long long KeySlave;
78 }SSP_KEYS;
79 
80 
81 
82 
83 
84 
85 /* command status enumeration */
86 typedef enum{
87  PORT_CLOSED,
88  PORT_OPEN,
89  PORT_ERROR,
90  SSP_REPLY_OK,
91  SSP_PACKET_ERROR,
92  SSP_CMD_TIMEOUT,
93 }PORT_STATUS;
94 
95 typedef struct {
96  SSP_FULL_KEY Key;
97  unsigned long Timeout;
98  unsigned char SSPAddress;
99  unsigned char RetryLevel;
100  unsigned char EncryptionStatus;
101  SSP_PORT port;
103 
104 typedef struct {
105  unsigned char event;
106  unsigned long data;
108 
109 typedef struct {
110  SSP_POLL_EVENT events[20];
111  unsigned char event_count;
112 } SSP_POLL_DATA;
113 
114 typedef struct{
115  unsigned char UnitType;
116  char FirmwareVersion[5];
117  char CountryCode[4];
118  unsigned long ValueMultiplier;
119  unsigned char ProtocolVersion;
121 
122 typedef struct{
123  unsigned char NumberOfChannels;
124  unsigned char ChannelData[16];
126 
127 typedef struct {
128  unsigned char UnitType;
129  char FirmwareVersion[5];
130  char CountryCode[4];
131  unsigned long ValueMultiplier;
132  SSP_CHANNEL_DATA ChannelValues;
133  SSP_CHANNEL_DATA ChannelSecurity;
134  unsigned long RealValueMultiplier;
135  unsigned char ProtocolVersion;
137 
138 
139 
140 /*
141 Name: SSPSendCommand
142 Inputs:
143  SSP_PORT The port handle (returned from OpenSSPPort) of the port to use
144  SSP_COMMAND The command structure to be used.
145 Return:
146  1 on success
147  0 on failure
148 Notes:
149  In the ssp_command structure:
150  EncryptionStatus,SSPAddress,Timeout,RetryLevel,CommandData,CommandDataLength (and Key if using encrpytion) must be set before calling this function
151  ResponseStatus,ResponseData,ResponseDataLength will be altered by this function call.
152 */
153 int SSPSendCommand(const SSP_PORT,SSP_COMMAND* cmd);
154 
155 /*
156 Name: OpenSSPPort
157 Inputs:
158  char * port: The name of the port to use (eg /dev/ttyUSB0 for usb serial, /dev/ttyS0 for com port 1)
159 Return:
160  -1 on error
161 Notes:
162 */
163 SSP_PORT OpenSSPPort(const char * port);
164 
165 
166 
167 /*
168 Name: CloseSSPPort
169 Inputs:
170  SSP_PORT port: The port you wish to close
171 Return:
172  void
173 Notes:
174 */
175 void CloseSSPPort(const SSP_PORT port);
176 
177 
178 
179 
180 /*
181 Name: DownloadFileToTarget
182 Inputs:
183  char *file: The full path of the file to download
184  char * port: The name of the port to use (eg /dev/ttyUSB0 for usb serial, /dev/ttyS0 for com port 1)
185  unsigned char sspAddress: The ssp address to download to
186  key: The encryption key to use. 0 to disable encryption
187 Return:
188  If the value is less than 0x100000 it is the number of blocks to be downloaded.
189  On an error, the value will be greater than 0x100000, and one of the following
190  Failure:
191  OPEN_FILE_ERROR 0x100001
192  READ_FILE_ERROR 0x100002
193  NOT_ITL_FILE 0x100003
194  PORT_OPEN_FAIL 0x100004
195  SYNC_CONNECTION_FAIL 0x100005
196  SECURITY_PROTECTED_FILE 0x100006
197  DATA_TRANSFER_FAIL 0x100010
198  PROG_COMMAND_FAIL 0x100011
199  HEADER_FAIL 0x100012
200  PROG_STATUS_FAIL 0x100013
201  PROG_RESET_FAIL 0x100014
202  DOWNLOAD_NOT_ALLOWED 0x100015
203  HI_TRANSFER_SPEED_FAIL 0x100016
204 Notes:
205  The download is done in a seperate thread - see GetDownloadStatus() for information about its progress.
206  Only one download operation may be in progress at once.
207 */
208 int DownloadFileToTarget(const char * file, const char * port, const unsigned char sspAddress, const unsigned long long key);
209 
210 /*
211 Name: DownloadDataToTarget
212 Inputs:
213  char * data: The array of data you wish to download
214  long data_length: length of data to download
215  char * port: The name of the port to use (eg /dev/ttyUSB0 for usb serial, /dev/ttyS0 for com port 1)
216  unsigned char sspAddress: The ssp address to download to
217  key: The encryption key to use. 0 to disable encryption
218 Return:
219  If the value is less than 0x100000 it is the number of blocks to be downloaded.
220  On an error, the value will be greater than 0x100000, and one of the following
221  Failure:
222  OPEN_FILE_ERROR 0x100001
223  READ_FILE_ERROR 0x100002
224  NOT_ITL_FILE 0x100003
225  PORT_OPEN_FAIL 0x100004
226  SYNC_CONNECTION_FAIL 0x100005
227  SECURITY_PROTECTED_FILE 0x100006
228  DATA_TRANSFER_FAIL 0x100010
229  PROG_COMMAND_FAIL 0x100011
230  HEADER_FAIL 0x100012
231  PROG_STATUS_FAIL 0x100013
232  PROG_RESET_FAIL 0x100014
233  DOWNLOAD_NOT_ALLOWED 0x100015
234  HI_TRANSFER_SPEED_FAIL 0x100016
235 Notes:
236  The download is done in a seperate thread - see GetDownloadStatus() for information about its progress
237  Only one download operation may be in progress at once.
238 */
239 int DownloadDataToTarget(const unsigned char* data, const unsigned long dlength, const char * cPort, const unsigned char sspAddress,const unsigned long long key);
240 
241 /*
242 Name: GetDownloadStatus
243 Inputs:
244  None
245 Return:
246  If the value is less than 0x100000 it is the block number being downloaded.
247  After the download process has finished (either successfully or not), the value will be 0x100000 (DOWNLOAD_COMPLETE) for a complete download
248  or one of the following for a failure:
249  OPEN_FILE_ERROR 0x100001
250  READ_FILE_ERROR 0x100002
251  NOT_ITL_FILE 0x100003
252  PORT_OPEN_FAIL 0x100004
253  SYNC_CONNECTION_FAIL 0x100005
254  SECURITY_PROTECTED_FILE 0x100006
255  DATA_TRANSFER_FAIL 0x100010
256  PROG_COMMAND_FAIL 0x100011
257  HEADER_FAIL 0x100012
258  PROG_STATUS_FAIL 0x100013
259  PROG_RESET_FAIL 0x100014
260  DOWNLOAD_NOT_ALLOWED 0x100015
261  HI_TRANSFER_SPEED_FAIL 0x100016
262 Notes:
263 
264 */
265 unsigned long GetDownloadStatus(void);
266 
267 /*
268 Name: NegotiateSSPEncryption
269 Inputs:
270  SSP_PORT The port handle (returned from OpenSSPPort) of the port to use
271  char ssp_address: The ssp_address to negotiate on
272  SSP_FULL_KEY * key: The ssp encryption key to be used
273 Return:
274  1 on success
275  0 on failure
276 Notes:
277  Only the EncryptKey iin SSP_FULL_KEY will be set. The FixedKey needs to be set by the user
278 */
279 int NegotiateSSPEncryption(SSP_PORT port, const char ssp_address, SSP_FULL_KEY * key);
280 
281 
282 //SSP functions
283 /*
284 The following functions all have an argument of type SSP_COMMAND_SETUP. This contains the information needed to send the command.
285 The user needs to set:
286  EncryptionStatus to NO_ENCRYPTION
287  SSPAddress to the sspaddress
288  port to the SSP_PORT handle
289  RetryLevel to the number of retrys
290  Timeout to the required timeout (in milliseconds)
291 */
292 /*
293 Name: ssp_setup_encryption
294 Inputs:
295  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
296  unsigned long long fixedkey: The fixed key to be used for SSP Encryption. The default key is 0x0123456701234567
297 Return:
298  SSP_RESPONSE_OK on success
299  On failure any other valid SSP_RESPONSE_ENUM value may be returned
300 Notes:
301  This will set the EncryptionStatus and Key in the SSP_COMMAND_SETUP so any further commands sent with this setup are encrypted.
302 */
303 SSP_RESPONSE_ENUM ssp_setup_encryption(SSP_COMMAND_SETUP * setup,const unsigned long long fixedkey);
304 
305 /*
306 Name: ssp_reset
307 Inputs:
308  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
309 Return:
310  SSP_RESPONSE_OK on success. Unit will then reset
311  On failure any other valid SSP_RESPONSE_ENUM value may be returned
312 Notes:
313 */
314 SSP_RESPONSE_ENUM ssp_reset(SSP_COMMAND_SETUP setup);
315 
316 /*
317 Name: ssp_host_protocol
318 Inputs:
319  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
320  unsigned char host_protocol : The version of protocol the host is trying to use
321 Return:
322  SSP_RESPONSE_OK on success
323  On failure any other valid SSP_RESPONSE_ENUM value may be returned
324 Notes:
325 */
326 SSP_RESPONSE_ENUM ssp_host_protocol(SSP_COMMAND_SETUP setup,const unsigned char host_protocol);
327 
328 /*
329 Name: ssp_poll
330 Inputs:
331  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
332  SSP_POLL_DATA * poll_response: A pointer to a poll response structure
333 Return:
334  SSP_RESPONSE_OK on success
335  On failure any other valid SSP_RESPONSE_ENUM value may be returned
336 Notes:
337 */
338 SSP_RESPONSE_ENUM ssp_poll(SSP_COMMAND_SETUP setup,SSP_POLL_DATA * poll_response);
339 
340 /*
341 Name: ssp_get_serial
342 Inputs:
343  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
344  SSP_POLL_DATA * poll_response: A pointer a long value to store the serial in
345 Return:
346  SSP_RESPONSE_OK on success
347  On failure any other valid SSP_RESPONSE_ENUM value may be returned
348 Notes:
349 */
350 SSP_RESPONSE_ENUM ssp_get_serial(SSP_COMMAND_SETUP setup,unsigned long * serial );
351 
352 /*
353 Name: ssp_sync
354 Inputs:
355  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
356 Return:
357  SSP_RESPONSE_OK on success
358  On failure any other valid SSP_RESPONSE_ENUM value may be returned
359 Notes:
360 */
361 SSP_RESPONSE_ENUM ssp_sync(SSP_COMMAND_SETUP setup);
362 
363 /*
364 Name: ssp_disable
365 Inputs:
366  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
367 Return:
368  SSP_RESPONSE_OK on success
369  On failure any other valid SSP_RESPONSE_ENUM value may be returnedNotes:
370 */
371 SSP_RESPONSE_ENUM ssp_disable(SSP_COMMAND_SETUP setup);
372 
373 /*
374 Name: ssp_enable
375 Inputs:
376  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
377 Return:
378  SSP_RESPONSE_OK on success
379  On failure any other valid SSP_RESPONSE_ENUM value may be returned
380 Notes:
381 */
382 SSP_RESPONSE_ENUM ssp_enable(SSP_COMMAND_SETUP setup);
383 
384 /*
385 Name: ssp_set_inhibits
386 Inputs:
387  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
388  unsigned char lowchannels: Bitmask setting inhibits for the low channels (1-8). A value of 1 in the bit means that channel is enabled
389  unsigned char highchannels: Bitmask setting inhibits for the low channels (9-16). A value of 1 in the bit means that channel is enabled
390 Return:
391  SSP_RESPONSE_OK on success
392  On failure any other valid SSP_RESPONSE_ENUM value may be returned
393 Notes:
394 */
395 SSP_RESPONSE_ENUM ssp_set_inhibits(SSP_COMMAND_SETUP setup,const unsigned char lowchannels, const unsigned char highchannels);
396 
397 /*
398 Name: ssp_display_on
399 Inputs:
400  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
401 Return:
402  SSP_RESPONSE_OK on success
403  On failure any other valid SSP_RESPONSE_ENUM value may be returned
404 Notes:
405 */
406 SSP_RESPONSE_ENUM ssp_display_on(SSP_COMMAND_SETUP setup);
407 
408 /*
409 Name: ssp_display_off
410 Inputs:
411  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
412 Return:
413  SSP_RESPONSE_OK on success
414  On failure any other valid SSP_RESPONSE_ENUM value may be returned
415 Notes:
416 */
417 SSP_RESPONSE_ENUM ssp_display_off(SSP_COMMAND_SETUP setup);
418 
419 /*
420 Name: ssp_hold_note
421 Inputs:
422  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
423 Return:
424  SSP_RESPONSE_OK on success
425  On failure any other valid SSP_RESPONSE_ENUM value may be returned
426 Notes:
427  Will only be successful when the unit has a note in escrow
428 */
429 SSP_RESPONSE_ENUM ssp_hold_note(SSP_COMMAND_SETUP setup);
430 
431 /*
432 Name: ssp_unit_data
433 Inputs:
434  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
435  SSP_UNIT_DATA * sud: Pointer to an SSP_UNIT_DATA structure for the data to be stored in
436 Return:
437  SSP_RESPONSE_OK on success
438  On failure any other valid SSP_RESPONSE_ENUM value may be returned
439 Notes:
440 */
441 SSP_RESPONSE_ENUM ssp_unit_data(SSP_COMMAND_SETUP setup, SSP_UNIT_DATA * sud);
442 
443 /*
444 Name: ssp_enable_higher_protocol_events
445 Inputs:
446  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
447 Return:
448  SSP_RESPONSE_OK on success
449  On failure any other valid SSP_RESPONSE_ENUM value may be returned
450 Notes:
451 */
452 SSP_RESPONSE_ENUM ssp_enable_higher_protocol_events(SSP_COMMAND_SETUP setup);
453 
454 /*
455 Name: ssp_channel_value_data
456 Inputs:
457  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
458  SSP_CHANNEL_DATA * scd: Pointer to an SSP_CHANNEL_DATA structure for the data to be stored in
459 Return:
460  SSP_RESPONSE_OK on success
461  On failure any other valid SSP_RESPONSE_ENUM value may be returned
462 Notes:
463 */
464 SSP_RESPONSE_ENUM ssp_channel_value_data(SSP_COMMAND_SETUP setup, SSP_CHANNEL_DATA * scd);
465 
466 /*
467 Name: ssp_channel_security_data
468 Inputs:
469  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
470  SSP_CHANNEL_DATA * scd: Pointer to an SSP_CHANNEL_DATA structure for the data to be stored in
471 Return:
472  SSP_RESPONSE_OK on success
473  On failure any other valid SSP_RESPONSE_ENUM value may be returned
474 Notes:
475 */
476 SSP_RESPONSE_ENUM ssp_channel_security_data(SSP_COMMAND_SETUP setup, SSP_CHANNEL_DATA * scd);
477 
478 /*
479 Name:
480 Inputs:
481  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
482  unsigned char * last_reject_reason: The reason for the last reject (See SSP Spec for more information)
483 Return:
484  SSP_RESPONSE_OK on success
485  On failure any other valid SSP_RESPONSE_ENUM value may be returned
486 Notes:
487 */
488 SSP_RESPONSE_ENUM ssp_last_reject(SSP_COMMAND_SETUP setup, unsigned char * last_reject_reason);
489 
490 /*
491 Name:
492 Inputs:
493  SSP_COMMAND_SETUP * setup: The ssp setup structure used to setup the command
494  SSP_SETUP_REQUEST_DATA * setup_request_data: Pointer to an SSP_CHANNEL_DATA structure for the data to be stored in
495 Return:
496  SSP_RESPONSE_OK on success
497  On failure any other valid SSP_RESPONSE_ENUM value may be returned
498 Notes:
499 */
500 SSP_RESPONSE_ENUM ssp_setup_request(SSP_COMMAND_SETUP setup, SSP_SETUP_REQUEST_DATA * setup_request_data);
501 
502 #ifdef __cplusplus
503 }
504 #endif
505 
506 #endif
Definition: SSPComs.h:55
Definition: SSPComs.h:104
Definition: port_win32_ssp.h:35
Definition: SSPComs.h:122
Definition: port_win32_ssp.h:67
void setup(struct m_metacash *metacash)
Initializes and configures redis, libevent and the hardware.
Definition: payoutd.c:1610
Definition: SSPComs.h:95
Definition: port_win32_ssp.h:30
Definition: SSPComs.h:114
Definition: port_win32_ssp.h:51
Definition: SSPComs.h:109
Definition: SSPComs.h:127