00351 :
00352
00353 This routine receives a packet from
the host machine that
is running
00354
the kernel debugger
UI. This routine
is ALWAYS called after packet being
00355 sent by caller. It first waits
for ACK packet
for the packet sent and
00356 then waits
for the packet desired.
00357
00358 N.B. If caller
is KdPrintString,
the parameter PacketType
is
00359 PACKET_TYPE_KD_ACKNOWLEDGE. In
this case,
this routine will
return
00360 right after
the ack packet
is received.
00361
00362 Arguments:
00363
00364 PacketType - Supplies
the type of packet that
is excepted.
00365
00366 MessageHeader - Supplies a pointer to a string descriptor
for the input
00367 message.
00368
00369 MessageData - Supplies a pointer to a string descriptor
for the input data.
00370
00371 DataLength - Supplies pointer to ULONG to receive length of recv. data.
00372
00373 Return Value:
00374
00375
KDP_PACKET_RESEND -
if resend
is required.
00376 KDP_PAKCET_TIMEOUT -
if timeout.
00377
KDP_PACKET_RECEIVED -
if packet received.
00378
00379 --*/
00380
00381 {
00382
00383 UCHAR Input;
00384 ULONG MessageLength;
00385 KD_PACKET PacketHeader;
00386 ULONG ReturnCode;
00387 ULONG Checksum;
00388
00389 WaitForPacketLeader:
00390
00391
00392
00393
00394
00395 ReturnCode =
KdpReceivePacketLeader(PacketType, &PacketHeader.PacketLeader);
00396
00397
00398
00399
00400
00401
00402
if (ReturnCode !=
KDP_PACKET_TIMEOUT) {
00403
KdpNumberRetries =
KdpRetryCount;
00404 }
00405
if (ReturnCode !=
KDP_PACKET_RECEIVED) {
00406
return ReturnCode;
00407 }
00408
00409
00410
00411
00412
00413 ReturnCode =
KdpReceiveString((PCHAR)&PacketHeader.PacketType,
00414
sizeof(PacketHeader.PacketType));
00415
if (ReturnCode ==
CP_GET_NODATA) {
00416
return KDP_PACKET_TIMEOUT;
00417 }
else if (ReturnCode ==
CP_GET_ERROR) {
00418
if (PacketHeader.PacketLeader == CONTROL_PACKET_LEADER) {
00419
00420
00421
00422
00423
00424
00425
00426
00427
goto WaitForPacketLeader;
00428 }
else {
00429
00430
00431
00432
00433
00434
00435
goto SendResendPacket;
00436 }
00437 }
00438
00439
00440
00441
00442
00443
00444
if ( PacketHeader.PacketLeader == CONTROL_PACKET_LEADER &&
00445 PacketHeader.PacketType == PACKET_TYPE_KD_RESEND ) {
00446
return KDP_PACKET_RESEND;
00447 }
00448
00449
00450
00451
00452
00453 ReturnCode =
KdpReceiveString((PCHAR)&PacketHeader.ByteCount,
00454
sizeof(PacketHeader.ByteCount));
00455
if (ReturnCode ==
CP_GET_NODATA) {
00456
return KDP_PACKET_TIMEOUT;
00457 }
else if (ReturnCode ==
CP_GET_ERROR) {
00458
if (PacketHeader.PacketLeader == CONTROL_PACKET_LEADER) {
00459
goto WaitForPacketLeader;
00460 }
else {
00461
goto SendResendPacket;
00462 }
00463 }
00464
00465
00466
00467
00468
00469 ReturnCode =
KdpReceiveString((PCHAR)&PacketHeader.PacketId,
00470
sizeof(PacketHeader.PacketId));
00471
00472
if (ReturnCode ==
CP_GET_NODATA) {
00473
return KDP_PACKET_TIMEOUT;
00474 }
else if (ReturnCode ==
CP_GET_ERROR) {
00475
if (PacketHeader.PacketLeader == CONTROL_PACKET_LEADER) {
00476
goto WaitForPacketLeader;
00477 }
else {
00478
goto SendResendPacket;
00479 }
00480 }
00481
00482
00483
00484
00485
00486 ReturnCode =
KdpReceiveString((PCHAR)&PacketHeader.Checksum,
00487
sizeof(PacketHeader.Checksum));
00488
if (ReturnCode ==
CP_GET_NODATA) {
00489
return KDP_PACKET_TIMEOUT;
00490 }
else if (ReturnCode ==
CP_GET_ERROR) {
00491
if (PacketHeader.PacketLeader == CONTROL_PACKET_LEADER) {
00492
goto WaitForPacketLeader;
00493 }
else {
00494
goto SendResendPacket;
00495 }
00496 }
00497
00498
00499
00500
00501
00502
00503
if (PacketHeader.PacketLeader == CONTROL_PACKET_LEADER ) {
00504
if (PacketHeader.PacketType == PACKET_TYPE_KD_ACKNOWLEDGE ) {
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
if (PacketHeader.PacketId !=
00515 (
KdpNextPacketIdToSend & ~SYNC_PACKET_ID)) {
00516
goto WaitForPacketLeader;
00517 }
else if (PacketType == PACKET_TYPE_KD_ACKNOWLEDGE) {
00518
KdpNextPacketIdToSend ^= 1;
00519
return KDP_PACKET_RECEIVED;
00520 }
else {
00521
goto WaitForPacketLeader;
00522 }
00523 }
else if (PacketHeader.PacketType == PACKET_TYPE_KD_RESET) {
00524
00525
00526
00527
00528
00529
00530
KdpNextPacketIdToSend = INITIAL_PACKET_ID;
00531
KdpPacketIdExpected = INITIAL_PACKET_ID;
00532
KdpSendControlPacket(PACKET_TYPE_KD_RESET, 0L);
00533
return KDP_PACKET_RESEND;
00534 }
else if (PacketHeader.PacketType == PACKET_TYPE_KD_RESEND) {
00535
return KDP_PACKET_RESEND;
00536 }
else {
00537
00538
00539
00540
00541
00542
goto WaitForPacketLeader;
00543 }
00544
00545
00546
00547
00548
00549 }
else if (PacketType == PACKET_TYPE_KD_ACKNOWLEDGE) {
00550
00551
00552
00553
00554
00555
00556
00557
00558
if (PacketHeader.PacketId ==
KdpPacketIdExpected) {
00559
KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0L);
00560
KdpNextPacketIdToSend ^= 1;
00561
return KDP_PACKET_RECEIVED;
00562 }
else {
00563
KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE,
00564 PacketHeader.PacketId
00565 );
00566
goto WaitForPacketLeader;
00567 }
00568 }
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 MessageLength = MessageHeader->MaximumLength;
00581
if ((PacketHeader.ByteCount > (
USHORT)PACKET_MAX_SIZE) ||
00582 (PacketHeader.ByteCount < (
USHORT)MessageLength)) {
00583
goto SendResendPacket;
00584 }
00585 *DataLength = PacketHeader.ByteCount - MessageLength;
00586
00587
00588
00589
00590
00591 ReturnCode =
KdpReceiveString(MessageHeader->Buffer, MessageLength);
00592
if (ReturnCode !=
CP_GET_SUCCESS) {
00593
goto SendResendPacket;
00594 }
00595 MessageHeader->Length = (
USHORT)MessageLength;
00596
00597
00598
00599
00600
00601 ReturnCode =
KdpReceiveString(MessageData->Buffer, *DataLength);
00602
if (ReturnCode !=
CP_GET_SUCCESS) {
00603
goto SendResendPacket;
00604 }
00605 MessageData->Length = (
USHORT)*DataLength;
00606
00607
00608
00609
00610
00611 ReturnCode =
KdPortGetByte(&Input);
00612
if (ReturnCode !=
CP_GET_SUCCESS || Input != PACKET_TRAILING_BYTE) {
00613
goto SendResendPacket;
00614 }
00615
00616
00617
00618
00619
00620
if (PacketType != PacketHeader.PacketType) {
00621
KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE,
00622 PacketHeader.PacketId
00623 );
00624
goto WaitForPacketLeader;
00625 }
00626
00627
00628
00629
00630
00631
if (PacketHeader.PacketId == INITIAL_PACKET_ID ||
00632 PacketHeader.PacketId == (INITIAL_PACKET_ID ^ 1)) {
00633
if (PacketHeader.PacketId !=
KdpPacketIdExpected) {
00634
KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE,
00635 PacketHeader.PacketId
00636 );
00637
goto WaitForPacketLeader;
00638 }
00639 }
else {
00640
goto SendResendPacket;
00641 }
00642
00643
00644
00645
00646
00647 Checksum =
KdpComputeChecksum(
00648 MessageHeader->Buffer,
00649 MessageHeader->Length
00650 );
00651
00652 Checksum +=
KdpComputeChecksum(
00653 MessageData->Buffer,
00654 MessageData->Length
00655 );
00656
if (Checksum != PacketHeader.Checksum) {
00657
goto SendResendPacket;
00658 }
00659
00660
00661
00662
00663
00664
00665
KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE,
00666 PacketHeader.PacketId
00667 );
00668
00669
00670
00671
00672
00673
00674
KdpPacketIdExpected ^= 1;
00675
return KDP_PACKET_RECEIVED;
00676
00677 SendResendPacket:
00678
KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0L);
00679
goto WaitForPacketLeader;
00680 }