Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. slipframe.c
  5. Abstract:
  6. Author:
  7. Thomas J. Dimitri (TommyD)
  8. Environment:
  9. Revision History:
  10. Ray Patch (raypa) 04/13/94 Modified for new WAN wrapper.
  11. --*/
  12. #include "asyncall.h"
  13. VOID
  14. AssembleSLIPFrame(
  15. PNDIS_WAN_PACKET pFrame)
  16. {
  17. PUCHAR pOldFrame;
  18. PUCHAR pNewFrame;
  19. UINT dataSize;
  20. UCHAR c;
  21. //
  22. // Initialize locals
  23. //
  24. pOldFrame=pFrame->CurrentBuffer;
  25. pNewFrame =pFrame->StartBuffer;
  26. //
  27. // for quicker access, get a copy of data length field
  28. //
  29. dataSize=pFrame->CurrentLength;
  30. //
  31. // Now we run through the entire frame and pad it FORWARDS...
  32. //
  33. // <------------- new frame -----------> (could be twice as large)
  34. // +-----------------------------------+
  35. // | |x|
  36. // +-----------------------------------+
  37. // ^
  38. // <---- old frame --> |
  39. // +-----------------+ |
  40. // | |x| |
  41. // +-----------------+ |
  42. // | |
  43. // \-----------------/
  44. //
  45. //
  46. //
  47. // 192 is encoded as 219, 220
  48. // 219 is encoded as 219, 221
  49. //
  50. *pNewFrame++ = SLIP_END_BYTE; // 192 - mark beginning of frame
  51. //
  52. // loop to remove all 192 and 219 chars
  53. //
  54. while ( dataSize-- ) {
  55. c = *pOldFrame++;
  56. //
  57. // Check if we have to escape out this byte or not
  58. //
  59. switch (c) {
  60. case SLIP_END_BYTE:
  61. *pNewFrame++ = SLIP_ESC_BYTE;
  62. *pNewFrame++ = SLIP_ESC_END_BYTE;
  63. break;
  64. case SLIP_ESC_BYTE:
  65. *pNewFrame++ = SLIP_ESC_BYTE;
  66. *pNewFrame++ = SLIP_ESC_ESC_BYTE;
  67. break;
  68. default:
  69. *pNewFrame++ = c;
  70. }
  71. }
  72. //
  73. // Mark end of frame
  74. //
  75. *pNewFrame++ = SLIP_END_BYTE;
  76. //
  77. // Calc how many bytes we expanded to including CRC
  78. //
  79. pFrame->CurrentLength = (ULONG)(pNewFrame - pFrame->StartBuffer);
  80. //
  81. // Put in the adjusted length -- actual num of bytes to send
  82. //
  83. pFrame->CurrentBuffer = pFrame->StartBuffer;
  84. }