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