-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
cmd_parser.c
746 lines (632 loc) · 16.6 KB
/
cmd_parser.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
/* stuff for receiving commands etc */
/* (c) copyright fenugrec 2016
* GPLv3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stypes.h"
#include <string.h> //memcpy
#include "npk_ver.h"
#include "platf.h"
#include "eep_funcs.h"
#include "iso_cmds.h"
#include "npk_errcodes.h"
#include "crc.h"
#define MAX_INTERBYTE 10 //ms between bytes that causes a disconnect
/* concatenate the ReadECUID positive response byte
* in front of the version string
*/
static const u8 npk_ver_string[] = SID_RECUID_PRC NPK_VER;
/* low-level error code, to give more detail about errors than the SID 7F NRC can provide,
* without requiring the error string list of nisprog to be updated.
*/
static u8 lasterr = 0;
/* make receiving slightly easier maybe */
struct iso14230_msg {
int hdrlen; //expected header length : 1 (len-in-fmt), 2(fmt + len), 3(fmt+addr), 4(fmt+addr+len)
int datalen; //expected data length
int hi; //index in hdr[]
int di; //index in data[]
u8 hdr[4];
u8 data[256]; //255 data bytes + checksum
};
/* generic buffer to construct responses. Saves a lot of stack vs
* each function declaring its buffer as a local var : gcc tends to inline everything
* but not combine /overlap each buffer.
* We just need to make sure the comms functions (iso_sendpkt, tx_7F etc) use their own
* private buffers. */
static u8 txbuf[256];
void set_lasterr(u8 err) {
lasterr = err;
}
/** simple 8-bit sum */
static uint8_t cks_u8(const uint8_t * data, unsigned int len) {
uint8_t rv=0;
while (len > 0) {
len--;
rv += data[len];
}
return rv;
}
/* sign-extend 24bit number to 32bits,
* i.e. FF8000 => FFFF8000 etc
* data stored as big (sh) endian
*/
static u32 reconst_24(const u8 *data) {
u32 tmp;
tmp = (data[0] << 16) | (data[1] << 8) | data[2];
if (data[0] & 0x80) {
//sign-extend to cover RAM
tmp |= 0xFF << 24;
}
return tmp;
}
/** discard RX data until idle for a given time
* @param idle : purge until interbyte > idle ms
*
* blocking, of course. Do not call from ISR
*/
static void sci_rxidle(unsigned ms) {
u32 t0, tc, intv;
if (ms > MCLK_MAXSPAN) ms = MCLK_MAXSPAN;
intv = MCLK_GETTS(ms); //# of ticks for delay
t0 = get_mclk_ts();
while (1) {
tc = get_mclk_ts();
if ((tc - t0) >= intv) return;
if (NPK_SCI.SSR.BYTE & 0x78) {
/* RDRF | ORER | FER | PER :reset timer */
t0 = get_mclk_ts();
NPK_SCI.SSR.BYTE &= 0x87; //clear RDRF + error flags
}
}
}
/** send a whole buffer, blocking. For use by iso_sendpkt() only */
static void sci_txblock(const uint8_t *buf, uint32_t len) {
for (; len > 0; len--) {
while (!NPK_SCI.SSR.BIT.TDRE) {} //wait for empty
NPK_SCI.TDR = *buf;
buf++;
NPK_SCI.SSR.BIT.TDRE = 0; //start tx
}
}
/** Send a headerless iso14230 packet
* @param len is clipped to 0xff
*
* disables RX during sending to remove halfdup echo. Should be reliable since
* we re-enable after the stop bit, so K should definitely be back up to '1' again
*
* this is blocking
*/
static void iso_sendpkt(const uint8_t *buf, int len) {
u8 hdr[2];
uint8_t cks;
if (len <= 0) return;
if (len > 0xff) len = 0xff;
NPK_SCI.SCR.BIT.RE = 0;
if (len <= 0x3F) {
hdr[0] = (uint8_t) len;
sci_txblock(hdr, 1); //FMT/Len
} else {
hdr[0] = 0;
hdr[1] = (uint8_t) len;
sci_txblock(hdr, 2); //Len
}
sci_txblock(buf, len); //Payload
cks = len;
cks += cks_u8(buf, len);
sci_txblock(&cks, 1); //cks
//ugly : wait for transmission end; this means re-enabling RX won't pick up a partial byte
while (!NPK_SCI.SSR.BIT.TEND) {}
NPK_SCI.SCR.BIT.RE = 1;
return;
}
/* transmit negative response, 0x7F <SID> <NRC>
* Blocking
*/
static void tx_7F(u8 sid, u8 nrc) {
u8 buf[3];
buf[0]=0x7F;
buf[1]=sid;
buf[2]=nrc;
iso_sendpkt(buf, 3);
}
static void iso_clearmsg(struct iso14230_msg *msg) {
msg->hdrlen = 0;
msg->datalen = 0;
msg->hi = 0;
msg->di = 0;
}
enum iso_prc { ISO_PRC_ERROR, ISO_PRC_NEEDMORE, ISO_PRC_DONE };
/** Add newly-received byte to msg;
*
* @return ISO_PRC_ERROR if bad header, bad checksum, or overrun (caller's fault)
* ISO_PRC_NEEDMORE if ok but msg not complete
* ISO_PRC_DONE when msg complete + good checksum
*
* Note : the *msg->hi, ->di, ->hdrlen, ->datalen memberes must be set to 0 before parsing a new message
*/
static enum iso_prc iso_parserx(struct iso14230_msg *msg, u8 newbyte) {
u8 dl;
// 1) new msg ?
if (msg->hi == 0) {
msg->hdrlen = 1; //at least 1 byte (FMT)
//parse FMT byte
if ((newbyte & 0xC0) == 0x40) {
//CARB mode, not supported
return ISO_PRC_ERROR;
}
if (newbyte & 0x80) {
//addresses supplied
msg->hdrlen += 2;
}
dl = newbyte & 0x3f;
if (dl == 0) {
/* Additional length byte present */
msg->hdrlen += 1;
} else {
/* len-in-fmt : we can set length already */
msg->datalen = dl;
}
}
// 2) add to header if required
if (msg->hi != msg->hdrlen) {
msg->hdr[msg->hi] = newbyte;
msg->hi += 1;
// fetch LEN byte if applicable
if ((msg->datalen == 0) && (msg->hi == msg->hdrlen)) {
msg->datalen = newbyte;
}
return ISO_PRC_NEEDMORE;
}
// ) here, header is complete. Add to data
msg->data[msg->di] = newbyte;
msg->di += 1;
// +1 because we need checksum byte too
if (msg->di != (msg->datalen + 1)) {
return ISO_PRC_NEEDMORE;
}
// ) data now complete. valide cks
u8 cks = cks_u8(msg->hdr, msg->hdrlen);
cks += cks_u8(msg->data, msg->datalen);
if (cks == msg->data[msg->datalen]) {
return ISO_PRC_DONE;
}
return ISO_PRC_ERROR;
}
/* Command state machine */
static enum t_cmdsm {
CM_IDLE, //not initted, only accepts the "startComm" request
CM_READY, //initted, accepts all commands
} cmstate;
/* flash state machine */
static enum t_flashsm {
FL_IDLE,
FL_READY, //after doing init.
} flashstate;
/* initialize command parser state machine;
* updates SCI settings : 62500 bps
* beware the FER error flag, it disables further RX. So when changing BRR, if the host sends a byte
* FER will be set, etc.
*/
void cmd_init(u8 brrdiv) {
cmstate = CM_IDLE;
flashstate = FL_IDLE;
NPK_SCI.SCR.BYTE &= 0xCF; //disable TX + RX
NPK_SCI.BRR = brrdiv; // speed = (div + 1) * 625k
NPK_SCI.SSR.BYTE &= 0x87; //clear RDRF + error flags
NPK_SCI.SCR.BYTE |= 0x30; //enable TX+RX , no RX interrupts for now
return;
}
static void cmd_startcomm(void) {
// KW : noaddr; len-in-fmt or lenbyte
static const u8 startcomm_resp[3] = {0xC1, 0x67, 0x8F};
iso_sendpkt(startcomm_resp, 3);
flashstate = FL_IDLE;
}
/* dump command processor, called from cmd_loop.
* args[0] : address space (0: EEPROM, 1: ROM)
* args[1,2] : # of 32-byte blocks
* args[3,4] : (address / 32)
*
* EEPROM addresses are interpreted as the flattened memory, i.e. 93C66 set as 256 * 16bit will
* actually be read as a 512 * 8bit array, so block #0 is bytes 0 to 31 == words 0 to 15.
*
* ex.: "00 00 02 00 01" dumps 64 bytes @ EEPROM 0x20 (== address 0x10 in 93C66)
* ex.: "01 80 00 00 00" dumps 1MB of ROM@ 0x0
*
*/
static void cmd_dump(struct iso14230_msg *msg) {
u32 addr;
u32 len;
u8 space;
u8 *args = &msg->data[1]; //skip SID byte
if (msg->datalen != 6) {
tx_7F(SID_DUMP, ISO_NRC_SFNS_IF);
return;
}
space = args[0];
len = 32 * ((args[1] << 8) | args[2]);
addr = 32 * ((args[3] << 8) | args[4]);
switch (space) {
case SID_DUMP_EEPROM:
/* dump eeprom stuff */
addr /= 2; /* modify address to fit with eeprom 256*16bit org */
len &= ~1; /* align to 16bits */
while (len) {
u16 pbuf[17];
u8 *pstart; //start of ISO packet
u16 *ebuf=&pbuf[1]; //cheat : form an ISO packet with the pos resp code in pbuf[0]
int pktlen;
int ecur;
pstart = (u8 *)(pbuf) + 1;
*pstart = SID_DUMP + 0x40;
pktlen = len;
if (pktlen > 32) pktlen = 32;
for (ecur = 0; ecur < (pktlen / 2); ecur += 1) {
eep_read16((uint8_t) addr + ecur, (uint16_t *)&ebuf[ecur]);
}
iso_sendpkt(pstart, pktlen + 1);
len -= pktlen;
addr += (pktlen / 2); //work in eeprom addresses
}
break;
case SID_DUMP_ROM:
/* dump from ROM */
txbuf[0] = SID_DUMP + 0x40;
while (len) {
int pktlen;
pktlen = len;
if (pktlen > 32) pktlen = 32;
memcpy(&txbuf[1], (void *) addr, pktlen);
iso_sendpkt(txbuf, pktlen + 1);
len -= pktlen;
addr += pktlen;
}
break;
default:
tx_7F(SID_DUMP, ISO_NRC_SFNS_IF);
break;
} //switch (space)
return;
}
/* SID 34 : prepare for reflashing */
static void cmd_flash_init(void) {
u8 errval;
if (!platf_flash_init(&errval)) {
tx_7F(SID_FLREQ, errval);
return;
}
txbuf[0] = (SID_FLREQ + 0x40);
iso_sendpkt(txbuf, 1);
flashstate = FL_READY;
return;
}
/* "one's complement" checksum; if adding causes a carry, add 1 to sum. Slightly better than simple 8bit sum
*/
static u8 cks_add8(u8 *data, unsigned len) {
u16 sum = 0;
for (; len; len--, data++) {
sum += *data;
if (sum & 0x100) sum += 1;
sum = (u8) sum;
}
return sum;
}
/* compare given CRC with calculated value.
* data is the first byte after SID_CONF_CKS1
*/
static int cmd_romcrc(const u8 *data) {
unsigned idx;
// <CNH> <CNL> <CRC0H> <CRC0L> ...<CRC3H> <CRC3L>
u16 chunkno = (*(data+0) << 8) | *(data+1);
for (idx = 0; idx < ROMCRC_NUMCHUNKS; idx++) {
u16 crc;
data += 2;
u16 test_crc = (*(data+0) << 8) | *(data+1);
u32 start = chunkno * ROMCRC_CHUNKSIZE;
crc = crc16((const u8 *)start, ROMCRC_CHUNKSIZE);
if (crc != test_crc) {
return -1;
}
chunkno += 1;
}
return 0;
}
/* handle low-level reflash commands */
static void cmd_flash_utils(struct iso14230_msg *msg) {
u8 subcommand;
u32 tmp;
u32 rv = ISO_NRC_GR;
if (flashstate != FL_READY) {
rv = ISO_NRC_CNCORSE;
goto exit_bad;
}
if (msg->datalen <= 1) {
rv = ISO_NRC_SFNS_IF;
goto exit_bad;
}
subcommand = msg->data[1];
switch(subcommand) {
case SIDFL_EB:
//format : <SID_FLASH> <SIDFL_EB> <BLOCKNO>
if (msg->datalen != 3) {
rv = ISO_NRC_SFNS_IF;
goto exit_bad;
}
rv = platf_flash_eb(msg->data[2]);
if (rv) {
rv = (rv & 0xFF) | 0x80; //make sure it's a valid extented NRC
goto exit_bad;
}
break;
case SIDFL_WB:
//format : <SID_FLASH> <SIDFL_WB> <A2> <A1> <A0> <D0>...<D127> <CRC>
if (msg->datalen != (SIDFL_WB_DLEN + 6)) {
rv = ISO_NRC_SFNS_IF;
goto exit_bad;
}
if (cks_add8(&msg->data[2], (SIDFL_WB_DLEN + 3)) != msg->data[SIDFL_WB_DLEN + 5]) {
rv = SID_CONF_CKS1_BADCKS; //crcerror
goto exit_bad;
}
tmp = (msg->data[2] << 16) | (msg->data[3] << 8) | msg->data[4];
rv = platf_flash_wb(tmp, (u32) &msg->data[5], SIDFL_WB_DLEN);
if (rv) {
rv = (rv & 0xFF) | 0x80; //make sure it's a valid extented NRC
goto exit_bad;
}
break;
case SIDFL_UNPROTECT:
//format : <SID_FLASH> <SIDFL_UNPROTECT> <~SIDFL_UNPROTECT>
if (msg->datalen != 3) {
rv = ISO_NRC_SFNS_IF;
goto exit_bad;
}
if (msg->data[2] != (u8) ~SIDFL_UNPROTECT) {
rv = ISO_NRC_IK; //InvalidKey
goto exit_bad;
}
platf_flash_unprotect();
break;
default:
rv = ISO_NRC_SFNS_IF;
goto exit_bad;
break;
}
txbuf[0] = SID_FLASH + 0x40;
iso_sendpkt(txbuf, 1); //positive resp
return;
exit_bad:
tx_7F(SID_FLASH, rv);
return;
}
/* ReadMemByAddress */
static void cmd_rmba(struct iso14230_msg *msg) {
//format : <SID_RMBA> <AH> <AM> <AL> <SIZ>
/* response : <SID + 0x40> <D0>....<Dn> <AH> <AM> <AL> */
u32 addr;
int siz;
if (msg->datalen != 5) goto bad12;
siz = msg->data[4];
if ((siz == 0) || (siz > 251)) goto bad12;
addr = reconst_24(&msg->data[1]);
txbuf[0] = SID_RMBA + 0x40;
memcpy(txbuf + 1, (void *) addr, siz);
siz += 1;
txbuf[siz++] = msg->data[1];
txbuf[siz++] = msg->data[2];
txbuf[siz++] = msg->data[3];
iso_sendpkt(txbuf, siz);
return;
bad12:
tx_7F(SID_RMBA, ISO_NRC_SFNS_IF);
return;
}
/* WriteMemByAddr - RAM only */
static void cmd_wmba(struct iso14230_msg *msg) {
/* WriteMemByAddress (RAM only !) . format : <SID_WMBA> <AH> <AM> <AL> <SIZ> <DATA> , siz <= 250. */
/* response : <SID + 0x40> <AH> <AM> <AL> */
u8 rv = ISO_NRC_SFNS_IF;
u32 addr;
u8 siz;
u8 *src;
if (msg->datalen < 6) goto badexit;
siz = msg->data[4];
if ( (siz == 0) ||
(siz > 250) ||
(msg->datalen != (siz + 5))) goto badexit;
addr = reconst_24(&msg->data[1]);
// bounds check, restrict to RAM
if ( (addr < RAM_MIN) ||
(addr > RAM_MAX)) {
rv = ISO_NRC_CNDTSA; /* canNotDownloadToSpecifiedAddress */
goto badexit;
}
/* write */
src = &msg->data[5];
memcpy((void *) addr, src, siz);
msg->data[0] = SID_WMBA + 0x40; //cheat !
iso_sendpkt(msg->data, 4);
return;
badexit:
tx_7F(SID_WMBA, rv);
return;
}
/* set & configure kernel */
static void cmd_conf(struct iso14230_msg *msg) {
u8 resp[4];
u32 tmp;
resp[0] = SID_CONF + 0x40;
if (msg->datalen < 2) goto bad12;
switch (msg->data[1]) {
case SID_CONF_SETSPEED:
/* set comm speed (BRR divisor reg) : <SID_CONF> <SID_CONF_SETSPEED> <new divisor> */
iso_sendpkt(resp, 1);
cmd_init(msg->data[2]);
sci_rxidle(25);
return;
break;
case SID_CONF_SETEEPR:
/* set eeprom_read() function address <SID_CONF> <SID_CONF_SETEEPR> <AH> <AM> <AL> */
if (msg->datalen != 5) goto bad12;
tmp = (msg->data[2] << 16) | (msg->data[3] << 8) | msg->data[4];
eep_setptr(tmp);
iso_sendpkt(resp, 1);
return;
break;
case SID_CONF_CKS1:
//<SID_CONF> <SID_CONF_CKS1> <CNH> <CNL> <CRC0H> <CRC0L> ...<CRC3H> <CRC3L>
if (msg->datalen != 12) {
goto bad12;
}
if (cmd_romcrc(&msg->data[2])) {
tx_7F(SID_CONF, SID_CONF_CKS1_BADCKS);
return;
}
iso_sendpkt(resp, 1);
return;
break;
case SID_CONF_LASTERR:
resp[1] = lasterr;
lasterr = 0;
iso_sendpkt(resp, 2);
return;
break;
#ifdef DIAG_U16READ
case SID_CONF_R16:
{
u16 val;
//<SID_CONF> <SID_CONF_R16> <A2> <A1> <A0>
tmp = reconst_24(&msg->data[2]);
tmp &= ~1; //clr lower bit of course
val = *(const u16 *) tmp;
resp[1] = val >> 8;
resp[2] = val & 0xFF;
iso_sendpkt(resp,3);
return;
break;
}
#endif
default:
goto bad12;
break;
}
bad12:
tx_7F(SID_CONF, ISO_NRC_SFNS_IF);
return;
}
/* command parser; infinite loop waiting for commands.
* not sure if it's worth the trouble to make this async,
* what other tasks could run in background ? reflash shit ?
*
* This receives valid iso14230 packets; message splitting is by pkt length
*/
void cmd_loop(void) {
u8 rxbyte;
static struct iso14230_msg msg;
//u32 t_last, t_cur; //timestamps
iso_clearmsg(&msg);
while (1) {
enum iso_prc prv;
/* in case of errors (ORER | FER | PER), reset state mach. */
if (NPK_SCI.SSR.BYTE & 0x38) {
cmstate = CM_IDLE;
flashstate = FL_IDLE;
iso_clearmsg(&msg);
sci_rxidle(MAX_INTERBYTE);
continue;
}
if (!NPK_SCI.SSR.BIT.RDRF) continue;
rxbyte = NPK_SCI.RDR;
NPK_SCI.SSR.BIT.RDRF = 0;
//t_cur = get_mclk_ts(); /* XXX TODO : filter out interrupted messages with t>5ms interbyte ? */
/* got a byte; parse according to state */
prv = iso_parserx(&msg, rxbyte);
if (prv == ISO_PRC_NEEDMORE) {
continue;
}
if (prv != ISO_PRC_DONE) {
iso_clearmsg(&msg);
sci_rxidle(MAX_INTERBYTE);
continue;
}
/* here, we have a complete iso frame */
switch (cmstate) {
case CM_IDLE:
/* accept only startcomm requests */
if (msg.data[0] == SID_STARTCOMM) {
cmd_startcomm();
cmstate = CM_READY;
}
iso_clearmsg(&msg);
break;
case CM_READY:
switch (msg.data[0]) {
case SID_STARTCOMM:
cmd_startcomm();
iso_clearmsg(&msg);
break;
case SID_RECUID:
iso_sendpkt(npk_ver_string, sizeof(npk_ver_string));
iso_clearmsg(&msg);
break;
case SID_CONF:
cmd_conf(&msg);
iso_clearmsg(&msg);
break;
case SID_RESET:
/* ECUReset */
txbuf[0] = msg.data[0] + 0x40;
iso_sendpkt(txbuf, 1);
die();
break;
case SID_RMBA:
cmd_rmba(&msg);
iso_clearmsg(&msg);
break;
case SID_WMBA:
cmd_wmba(&msg);
iso_clearmsg(&msg);
break;
case SID_DUMP:
cmd_dump(&msg);
iso_clearmsg(&msg);
break;
case SID_FLASH:
cmd_flash_utils(&msg);
iso_clearmsg(&msg);
break;
case SID_TP:
txbuf[0] = msg.data[0] + 0x40;
iso_sendpkt(txbuf, 1);
iso_clearmsg(&msg);
break;
case SID_FLREQ:
cmd_flash_init();
iso_clearmsg(&msg);
break;
default:
tx_7F(msg.data[0], ISO_NRC_SNS);
iso_clearmsg(&msg);
break;
} //switch (SID)
break;
default :
//invalid state, or nothing special to do
break;
} //switch (cmstate)
} //while 1
die();
}