source: trunk/csctapi/pps.c@ 1286

Last change on this file since 1286 was 1286, checked in by dingo35, 11 years ago

Move T1 timing aspects to pps.c and fix selected_protocol error

File size: 17.3 KB
Line 
1/*
2 pps.c
3 Protocol Parameters Selection
4
5 This file is part of the Unix driver for Towitoko smartcard readers
6 Copyright (C) 2000 2001 Carlos Prados <cprados@yahoo.com>
7
8 This version is modified by doz21 to work in a special manner ;)
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23*/
24
25#include "pps.h"
26#include "atr.h"
27#include "protocol_t0.h"
28#include "protocol_t1.h"
29#include <stdlib.h>
30#include <stdio.h>
31#include <string.h>
32#include "ifd.h"
33#include "../globals.h"
34
35/*
36 * Not exported constants definition
37 */
38
39#define PPS_DEFAULT_PROTOCOL 0x00
40#define PROTOCOL_T0_DEFAULT_WI 10
41
42#define PROTOCOL_T1_DEFAULT_IFSC 32
43#define PROTOCOL_T1_DEFAULT_IFSD 32
44#define PROTOCOL_T1_MAX_IFSC 251 /* Cannot send > 255 buffer */
45#define PROTOCOL_T1_DEFAULT_CWI 13
46#define PROTOCOL_T1_DEFAULT_BWI 4
47#define PROTOCOL_T1_EDC_LRC 0
48#define PROTOCOL_T1_EDC_CRC 1
49/*
50 * Not exported macros definition
51 */
52
53#define PPS_HAS_PPS1(block) ((block[1] & 0x10) == 0x10)
54#define PPS_HAS_PPS2(block) ((block[1] & 0x20) == 0x20)
55#define PPS_HAS_PPS3(block) ((block[1] & 0x40) == 0x40)
56
57/*
58 * Not exported funtions declaration
59 */
60
61static int PPS_Exchange (BYTE * params, unsigned *length);
62
63static bool PPS_Match (BYTE * request, unsigned len_request, BYTE * reply, unsigned len_reply);
64
65static unsigned PPS_GetLength (BYTE * block);
66
67static int PPS_InitICC ();
68
69static int PPS_InitProtocol ();
70
71static BYTE PPS_GetPCK (BYTE * block, unsigned length);
72
73/*
74 * Exported functions definition
75 */
76
77PPS * PPS_New ()
78{
79 PPS *pps;
80
81 pps = (PPS *) malloc (sizeof (PPS));
82
83 if (pps != NULL)
84 {
85 protocol = NULL;
86 parameters.t = PPS_DEFAULT_PROTOCOL;
87 parameters.FI = ATR_DEFAULT_FI;
88 parameters.d = ATR_DEFAULT_D;
89 parameters.n = ATR_DEFAULT_N;
90 }
91
92 return pps;
93}
94
95int PPS_Perform (PPS * pps, BYTE * params, unsigned *length)
96{
97 //Performs PPS Exchange on command when *length >0
98 //If unsuccesfull, or when length <= 0
99 //Gets parametes from ATR
100 //If necessary perform PPS session
101 //
102 //Output is pps->params.FI,n,d,t set with correct values
103 //and switched SC-device conform these values to correct baudrate
104 //
105 //We need to store FI instread of F, because SCI_DEV works with FI
106 //and it is easier to overclock then
107 //also from FI -> F is easy, other way around not
108
109 int ret;
110 bool PPS_success;
111
112 /* Perform PPS Exchange if requested by command */
113 if ((*length) > 0)
114 {
115 ret = PPS_Exchange (params, length);
116
117 /* Get parameters from PPS handsake */
118 if (ret == PPS_OK)
119 {
120 parameters.t = params[1] & 0x0F;
121
122 if (PPS_HAS_PPS1 (params))
123 {
124 parameters.FI = (params[2] >> 4);
125 parameters.d = atr_d_table[(params[2] & 0x0F)];
126 }
127
128/*
129 ret = PPS_InitICC(pps);
130
131 if (ret != PPS_OK)
132 return ret;
133*/
134 }
135/*
136 else
137 {
138 return ret;
139 }
140*/
141 }
142 PPS_success = PPS_OK;
143 int protocol_selected = 0; //stores which TAi,TBi etc. bytes must be used 0 means not set
144 if ((*length) <= 0 || !PPS_success) // If not by command, or PPS Exchange by command failed: Try PPS Exchange by ATR or Get parameters from ATR
145 {
146 int numprot = atr->pn;
147 //if there is a trailing TD, this number is one too high
148 BYTE tx;
149 if (ATR_GetInterfaceByte (atr, numprot-1, ATR_INTERFACE_BYTE_TD, &tx) == ATR_OK)
150 if ((tx & 0xF0) == 0)
151 numprot--;
152 cs_debug("ATR reports %i protocol lines:",numprot);
153 int i,point;
154 char txt[50];
155 bool OffersT[3]; //T14 stored as T2
156 for (i = 0; i <= 2; i++)
157 OffersT[i] = FALSE;
158 for (i=1; i<= numprot; i++) {
159 point = 0;
160 if (ATR_GetInterfaceByte (atr, i, ATR_INTERFACE_BYTE_TA, &tx) == ATR_OK) {
161 sprintf((char *)txt+point,"TA%i=%02X ",i,tx);
162 point +=7;
163 }
164 if (ATR_GetInterfaceByte (atr, i, ATR_INTERFACE_BYTE_TB, &tx) == ATR_OK) {
165 sprintf((char *)txt+point,"TB%i=%02X ",i,tx);
166 point +=7;
167 }
168 if (ATR_GetInterfaceByte (atr, i, ATR_INTERFACE_BYTE_TC, &tx) == ATR_OK) {
169 sprintf((char *)txt+point,"TC%i=%02X ",i,tx);
170 point +=7;
171 }
172 if (ATR_GetInterfaceByte (atr, i, ATR_INTERFACE_BYTE_TD, &tx) == ATR_OK) {
173 sprintf((char *)txt+point,"TD%i=%02X ",i,tx);
174 point +=7;
175 tx &= 0X0F;
176 sprintf((char *)txt+point,"(T%i)",tx);
177 if (tx == 14)
178 OffersT[2] = TRUE;
179 else
180 OffersT[tx] = TRUE;
181 }
182 else {
183 sprintf((char *)txt+point,"no TD%i means T0",i);
184 OffersT[0] = TRUE;
185 }
186 cs_debug("%s",txt);
187 }
188
189 int numprottype = 0;
190 for (i = 0; i <= 2; i++)
191 if (OffersT[i])
192 numprottype ++;
193 cs_debug("%i protocol types detected. Historical bytes: %s",numprottype, cs_hexdump(1,atr->hb,atr->hbn));
194
195//If more than one protocol type and/or TA1 parameter values other than the default values and/or N equeal to 255 is/are indicated in the answer to reset, the card shall know unambiguously, after having sent the answer to reset, which protocol type or/and transmission parameter values (FI, D, N) will be used. Consequently a selection of the protocol type and/or the transmission parameters values shall be specified.
196 ATR_GetParameter (atr, ATR_PARAMETER_N, &(parameters.n));
197 ATR_GetProtocolType(atr,1,&(parameters.t)); //get protocol from TD1
198 BYTE TA2;
199 bool SpecificMode = (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TA, &TA2) == ATR_OK); //if TA2 present, specific mode, else negotiable mode
200 if (SpecificMode) {
201 parameters.t = TA2 & 0x0F;
202 if ((TA2 & 0x10) != 0x10) { //bit 5 set to 0 means F and D explicitly defined in interface characters
203 BYTE TA1;
204 if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) {
205 parameters.FI = TA1 >> 4;
206 ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d));
207 }
208 else {
209 parameters.FI = ATR_DEFAULT_FI;
210 parameters.d = ATR_DEFAULT_D;
211 }
212 }
213 else {
214 cs_log("Specific mode: speed 'implicitly defined', not sure how to proceed, assuming default values");
215 parameters.FI = ATR_DEFAULT_FI;
216 parameters.d = ATR_DEFAULT_D;
217 }
218 cs_debug("Specific mode: T%i, F=%.0f, D=%.6f, N=%.0f\n", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
219 }
220 else { //negotiable mode
221
222 bool NeedsPTS = ((parameters.t != 14) && (numprottype > 1 || (atr->ib[0][ATR_INTERFACE_BYTE_TA].present == TRUE && atr->ib[0][ATR_INTERFACE_BYTE_TA].value != 0x11) || parameters.n == 255)); //needs PTS according to ISO 7816 , SCI gets stuck on our PTS
223 if (NeedsPTS) {
224 // PTSS PTS0 PTS1 PTS2 PTS3 PCK
225 // PTSS PTS0 PTS1 PCK
226 BYTE req[] = { 0xFF, 0x10, 0x00, 0x00 }; //we currently do not support PTS2, standard guardtimes
227 req[1]=0x10 | parameters.t; //PTS0 always flags PTS1 to be sent always
228 if (ATR_GetInterfaceByte (atr, 1, ATR_INTERFACE_BYTE_TA, &req[2]) != ATR_OK) //PTS1
229 req[2] = 0x11; //defaults FI and DI to 1
230 //req[3]=PPS_GetPCK(req,sizeof(req)-1); will be set by PPS_Exchange
231 unsigned int len = sizeof(req);
232 ret = PPS_Exchange (req, &len);
233 if (ret == PPS_OK) {
234 parameters.FI = req[2] >> 4;
235 BYTE DI = req[2] & 0x0F;
236 parameters.d = (double) (atr_d_table[DI]);
237 PPS_success = TRUE;
238 cs_debug("PTS Succesfull, selected protocol: T%i, F=%.0f, D=%.6f, N=%.0f\n", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
239 }
240 else
241 cs_ddump(req,4,"PTS Failure, response:");
242 }
243
244 //FIXME Currently InitICC sets baudrate to 9600 for all T14 cards (=no switching);
245 //When for SCI, T14 protocol, TA1 is obeyed, this goes OK for mosts devices, but somehow on DM7025 Sky S02 card goes wrong when setting ETU (ok on DM800/DM8000)
246 if (!PPS_success) {//last PPS not succesfull
247 BYTE TA1;
248 if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) {
249 parameters.FI = TA1 >> 4;
250 ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d));
251 }
252 else { //do not obey TA1
253 parameters.FI = ATR_DEFAULT_FI;
254 parameters.d = ATR_DEFAULT_D;
255 }
256 ATR_GetProtocolType (atr, 1, &(parameters.t));
257 protocol_selected = 1;
258
259 if (NeedsPTS) {
260 if ((parameters.d == 32) || (parameters.d == 12) || (parameters.d == 20))
261 parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this
262 }
263 /////Here all non-ISO behaviour
264 /////End all non-ISO behaviour
265
266 cs_debug("No PTS %s, selected protocol T%i, F=%.0f, D=%.6f, N=%.0f\n", NeedsPTS?"happened":"needed", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
267 }
268 }//end negotiable mode
269 }//end length<0
270
271 //make sure no zero values
272 double F = (double) atr_f_table[parameters.FI];
273 if (!F) {
274 parameters.FI = ATR_DEFAULT_FI;
275 cs_log("Warning: F=0 is invalid, forcing FI=%d", parameters.FI);
276 }
277 if (!parameters.d) {
278 parameters.d = ATR_DEFAULT_D;
279 cs_log("Warning: D=0 is invalid, forcing D=%.0f",parameters.d);
280 }
281
282 protocol_type = parameters.t;
283
284#ifdef DEBUG_PROTOCOL
285 printf("PPS: T=%i, F=%.0f, D=%.6f, N=%.0f\n",
286 parameters.t,
287 F,
288 parameters.d,
289 parameters.n);
290#endif
291
292 ret = PPS_InitICC(pps);
293
294 if (ret != PPS_OK)
295 return ret;
296
297 /* Initialize selected protocol with selected parameters */
298 return PPS_InitProtocol ();
299}
300
301void * PPS_GetProtocol ()
302{
303 return protocol;
304}
305
306PPS_ProtocolParameters *PPS_GetProtocolParameters ()
307{
308 /* User must Remember not to reference this struct after removing PPS */
309 return &(parameters);
310}
311
312void PPS_Delete (PPS * pps)
313{
314 free (pps);
315}
316
317/*
318 * Not exported funtions definition
319 */
320
321static int PPS_Exchange (BYTE * params, unsigned *length)
322{
323 BYTE confirm[PPS_MAX_LENGTH];
324 unsigned len_request, len_confirm;
325 int ret;
326#ifdef DEBUG_PROTOCOL
327 int i;
328#endif
329
330 len_request = PPS_GetLength (params);
331 params[len_request - 1] = PPS_GetPCK(params, len_request - 1);
332
333#ifdef DEBUG_PROTOCOL
334 printf ("PPS: Sending request: ");
335 for (i = 0; i < len_request; i++)
336 printf ("%X ", params[i]);
337 printf ("\n");
338#endif
339
340 cs_debug("PTS: Sending request: %s", cs_hexdump(1, params, len_request));
341
342 /* Send PPS request */
343#ifdef COOL
344 //unsigned char ptsAck[10];
345 //u_int8 ptsLen = len_request;
346 unsigned short int ptsLen = len_request;
347 int Status = cnxt_smc_start_pps(handle, params, confirm, &ptsLen, TRUE);
348 printf ("cnxt_smc_start_pps Status=%i\n", Status);
349 len_confirm = ptsLen;
350#ifdef DEBUG_PROTOCOL
351 printf("COOL: confirm: \n");
352 for (i = 0; i < ptsLen; i++)
353 printf ("%02X", confirm[i]);
354 printf ("\n");
355 fflush(stdout);
356 printf("COOL: req: \n");
357 for (i = 0; i < len_request; i++)
358 printf ("%02X", params[i]);
359 printf ("\n");
360 fflush(stdout);
361#endif
362 if (Status)
363 return PPS_HANDSAKE_ERROR;
364#else
365 if (ICC_Async_Transmit (len_request, params) != ICC_ASYNC_OK)
366 return PPS_ICC_ERROR;
367
368 /* Get PPS confirm */
369 if (ICC_Async_Receive (2, confirm) != ICC_ASYNC_OK)
370 return PPS_ICC_ERROR;
371
372 len_confirm = PPS_GetLength (confirm);
373
374 if (ICC_Async_Receive (len_confirm - 2, confirm + 2) != ICC_ASYNC_OK)
375 return PPS_ICC_ERROR;
376
377#ifdef DEBUG_PROTOCOL
378 printf ("PPS: Receivig confirm: ");
379 for (i = 0; i < len_confirm; i++)
380 printf ("%X ", confirm[i]);
381 printf ("\n");
382#endif
383
384 cs_debug("PTS: Receiving confirm: %s", cs_hexdump(1, confirm, len_confirm));
385
386 if (!PPS_Match (params, len_request, confirm, len_confirm))
387 ret = PPS_HANDSAKE_ERROR;
388 else
389 ret = PPS_OK;
390#endif
391
392 /* Copy PPS handsake */
393 memcpy (params, confirm, len_confirm);
394 (*length) = len_confirm;
395
396 return ret;
397}
398
399static bool PPS_Match (BYTE * request, unsigned len_request, BYTE * confirm, unsigned len_confirm)
400{
401 /* See if the reply differs from request */
402 if ((len_request != len_confirm) || (memcmp (request, confirm, len_request)))
403 {
404 /* See if the card specifies other than default FI and D */
405 //if ((PPS_HAS_PPS1 (confirm)) && (confirm[2] != request[2]))
406 return FALSE;
407 }
408
409 return TRUE;
410}
411
412static unsigned PPS_GetLength (BYTE * block)
413{
414 unsigned length = 3;
415
416 if (PPS_HAS_PPS1 (block))
417 length++;
418
419 if (PPS_HAS_PPS2 (block))
420 length++;
421
422 if (PPS_HAS_PPS3 (block))
423 length++;
424
425 return length;
426}
427
428static int PPS_InitICC ()
429{
430#ifdef SCI_DEV
431#include <sys/ioctl.h>
432#include "sci_global.h"
433#include "sci_ioctl.h"
434 if(reader[ridx].typ == R_INTERNAL)
435 {
436 int n;
437 SCI_PARAMETERS params;
438 //memset(&params,0,sizeof(SCI_PARAMETERS));
439 if (ioctl(reader[ridx].handle, IOCTL_GET_PARAMETERS, &params) < 0 )
440 return PPS_ICC_ERROR;
441
442 params.T = parameters.t;
443 params.fs = atr_fs_table[parameters.FI] / 1000000;
444 double F = (double) atr_f_table[parameters.FI];
445 //for Irdeto T14 cards, do not set ETU
446 if (!(atr->hbn >= 6 && !memcmp(atr->hb, "IRDETO", 6) && params.T == 14))
447 params.ETU = F / parameters.d;
448 if (parameters.n == 255) //only for T0 or also for T1?
449 params.EGT = 0;
450 else
451 params.EGT = parameters.n;
452
453 double a;
454 ATR_GetParameter(atr, ATR_PARAMETER_P, &a);
455 params.P=(unsigned char)a;
456 ATR_GetParameter(atr, ATR_PARAMETER_I, &a);
457 params.I=(unsigned char)a;
458
459 cs_debug("Setting T=%d fs=%lu mhz ETU=%d WWT=%d CWT=%d BWT=%d EGT=%d clock=%d check=%d P=%d I=%d U=%d", (int)params.T, params.fs, (int)params.ETU, (int)params.WWT, (int)params.CWT, (int)params.BWT, (int)params.EGT, (int)params.clock_stop_polarity, (int)params.check, (int)params.P, (int)params.I, (int)params.U);
460
461 if (ioctl(reader[ridx].handle, IOCTL_SET_PARAMETERS, &params)!=0)
462 return PPS_ICC_ERROR;
463
464 }
465#elif COOL
466 if(reader[ridx].typ == R_INTERNAL) {
467 int mhz = atr_fs_table[parameters.FI] / 10000;
468 if (!Cool_SetBaudrate(mhz))
469 return PPS_ICC_ERROR;
470#ifdef DEBUG_PROTOCOL
471 printf("Coolstream: set clock to %i * 10kHz\n", mhz);
472#endif
473 return PPS_OK;
474 }
475#endif
476 {
477 unsigned long baudrate;
478 double F = (double) atr_f_table[parameters.FI];
479 if (parameters.t == 14)
480 baudrate = 9600;
481 else
482 baudrate = parameters.d * ICC_Async_GetClockRate () / F;
483
484#ifdef DEBUG_PROTOCOL
485 printf ("PPS: Baudrate = %d\n", (int)baudrate);
486#endif
487
488
489 if (ICC_Async_SetBaudrate (baudrate) != ICC_ASYNC_OK)
490 return PPS_ICC_ERROR;
491
492 return PPS_OK;
493 }
494}
495
496int Protocol_T1_Init ()
497{
498 BYTE ta, tb, tc, cwi, bwi;
499 unsigned long baudrate;
500 double work_etu;
501 int i;
502
503 // Set IFSC
504 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TA, &ta) == ATR_NOT_FOUND)
505 ifsc = PROTOCOL_T1_DEFAULT_IFSC;
506 else if ((ta != 0x00) && (ta != 0xFF))
507 ifsc = ta;
508 else
509 ifsc = PROTOCOL_T1_DEFAULT_IFSC;
510
511 // Towitoko does not allow IFSC > 251 //FIXME not sure whether this limitation still exists
512 ifsc = MIN (ifsc, PROTOCOL_T1_MAX_IFSC);
513
514 // Set IFSD
515 ifsd = PROTOCOL_T1_DEFAULT_IFSD;
516
517#ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS
518 // Calculate CWI and BWI
519 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TB, &tb) == ATR_NOT_FOUND)
520 {
521#endif
522 cwi = PROTOCOL_T1_DEFAULT_CWI;
523 bwi = PROTOCOL_T1_DEFAULT_BWI;
524#ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS
525 }
526 else
527 {
528 cwi = tb & 0x0F;
529 bwi = (tb & 0xF0) >> 4;
530 }
531#endif
532
533 // Work etu = (1000 / baudrate) milliseconds
534 ICC_Async_GetBaudrate (&baudrate);
535 work_etu = 1000 / (double)baudrate;
536
537 // Set CWT = (2^CWI + 11) work etu
538 cwt = 1;
539
540 for (i = 0; i < cwi ; i++)
541 cwt *= 2;
542
543 cwt = (unsigned short) ((cwt + 11) * work_etu);
544
545 // Set BWT = (2^BWI * 960 + 11) work etu
546 bwt = 1;
547 for (i = 0; i < bwi; i++)
548 bwt *= 2;
549
550 bwt = (unsigned short) ((bwt * 960 + 11) * work_etu);
551
552 // Set BGT = 22 * work etu
553 bgt = (unsigned short) (22 * work_etu);
554
555 // Set the error detection code type
556 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TC, &tc) == ATR_NOT_FOUND)
557 edc = PROTOCOL_T1_EDC_LRC;
558 else
559 edc = tc & 0x01;
560
561 // Set initial send sequence (NS)
562 ns = 1;
563
564 // Set timings
565 icc_timings.block_timeout = bwt;
566 icc_timings.char_timeout = cwt;
567 icc_timings.block_delay = bgt;
568 ICC_Async_SetTimings ();
569
570#ifdef DEBUG_PROTOCOL
571 printf ("Protocol: T=1: IFSC=%d, IFSD=%d, CWT=%d, BWT=%d, BGT=%d, EDC=%s\n",
572 ifsc, ifsd, cwt, bwt, t1->bgt,
573 (edc == PROTOCOL_T1_EDC_LRC) ? "LRC" : "CRC");
574#endif
575
576 return PROTOCOL_T1_OK;
577}
578
579static int PPS_InitProtocol ()
580{
581 switch (parameters.t) {
582 case ATR_PROTOCOL_TYPE_T0:
583 case ATR_PROTOCOL_TYPE_T14:
584 {
585 BYTE wi;
586 /* Integer value WI = TC2, by default 10 */
587#ifndef PROTOCOL_T0_USE_DEFAULT_TIMINGS
588 if (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
589#endif
590 wi = PROTOCOL_T0_DEFAULT_WI;
591
592 /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */
593 double F = (double) atr_f_table[parameters.FI];
594 unsigned long wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
595 if (parameters.t == 14)
596 wwt >>= 1; //is this correct?
597
598 /* Set timings */
599 icc_timings.block_timeout = wwt;
600 icc_timings.char_timeout = wwt;
601 ICC_Async_SetTimings ();
602#ifdef DEBUG_PROTOCOL
603 printf ("Protocol: T=%i: WWT=%d, Clockrate=%lu\n", params->t, (int)(wwt),ICC_Async_GetClockRate());
604#endif
605 }
606 break;
607 case ATR_PROTOCOL_TYPE_T1:
608 Protocol_T1_Init ();//always returns ok
609 break;
610 default:
611 protocol = NULL;
612 return PPS_PROTOCOL_ERROR;
613 break;
614 }
615 return PPS_OK;
616}
617
618static BYTE PPS_GetPCK (BYTE * block, unsigned length)
619{
620 BYTE pck;
621 unsigned i;
622
623 pck = block[0];
624 for (i = 1; i < length; i++)
625 pck ^= block[i];
626
627 return pck;
628}
Note: See TracBrowser for help on using the repository browser.