-- File: DriverTypes.Mesa,  Last Edit: HGM  January 7, 1981  10:21 PM

DIRECTORY
  SpecialSystem USING [broadcastHostNumber, HostNumber, ProcessorID];

DriverTypes: DEFINITIONS =
  BEGIN

  Byte: TYPE = [0..377B];
  Nibble: TYPE = [0..17B];

  DeviceType: TYPE = {
    unknown, ethernet, ethernetOne, local, sla, arpanet, packetradio, phonenet,
    spare};

  HostNumber: TYPE = SpecialSystem.HostNumber;
  ProcessorID: TYPE = SpecialSystem.ProcessorID;


  -- ENCAPSULATION
  -- This lives here because it is common to Pup and Ois, and needs to be compiled before BufferDefs

  -- An instance of this record is the last thing in a Buffer before the real data block.  The hardware transfers bits to/from it and then keeps going into the body of the packet.  Note that the spare words are at the beginning of the record, not the end.  That way the driver can easily skip over them by just starting at the right place.


  -- BEWARE OF QUAD WORD ALIGNMENT HICKUPS    REALLY!!!!!!
  Encapsulation: TYPE = MACHINE DEPENDENT RECORD [
    SELECT OVERLAID DeviceType FROM
      local => [
	localSpare1, localSpare2, localSpare3, localSpare4, localSpare5: WORD,
	localHost: CARDINAL,
	localType: LocalPacketType],
      ethernet => [
	-- bits on the wire start here
	ethernetDest: HostNumber,
	ethernetSource: ProcessorID,
	ethernetType: EthernetPacketType],
      ethernetOne => [
	etherSpare1, etherSpare2, etherSpare3, etherSpare4: WORD,
	etherSpare5: [0..77777B],
	translationWorked: BOOLEAN,
	-- Bits on the ether start here
	ethernetOneDest, ethernetOneSource: Byte,
	ethernetOneType: EthernetOnePacketType],
      sla => [
	slaSpare1: WORD,
	slaSpare2: WORD,
	slaSpare3: [0..37777B],
	slaHi: BOOLEAN,
	slaBroadcast: BOOLEAN,
	slaTimeQueued: CARDINAL,
	slaSourceLine, slaDestHost: WORD, -- BEWARE: these don't get sent
	-- Bits on the line start here
	slaType: SlaPacketType],
      arpanet => [
	arpaSpare1, arpaSpare2, arpaSpare3, arpaSpare4, arpaSpare5: WORD,
	arpanetControl: Byte, -- 0 for "Regular message"
	arpanetHost: Byte, -- source if sending, dest if receiving
	arpanetLink: ArpanetLink,
	apranetZero: Byte],
      packetradio => [
	-- Larry Stewart
	prSpare1: WORD,
	prLength: WORD,
	timer: CARDINAL,
	prSequence: WORD,
	prBroadcast: BOOLEAN,
	numFrags, numFragsTrans, numFragsRcvd: [0..3],
	first, second, third: BOOLEAN,
	transCount: [0..77B],
	prAddress: WORD,
	prType: PRPacketType,
	prSpare: Nibble,
	prSpare2: Byte],
      phonenet => [
	-- Larry Garlick
	framing0, framing1, framing2, framing3, framing4, framing5: Byte,
	recognition: Byte, -- 0 for auto recognition of OISCP vs SDLC/HDLC
	pnType: PhonePacketType,
	pnSrcID: SpecialSystem.ProcessorID],
      spare => [spare1, spare2, spare3, spare4, spare5, spare6, spare7: WORD],
      ENDCASE];

  -- Many places will fall apart if SIZE[Encapsulation]#7.  Look carefully at the buffer allocation routines to be sure that the allignment works out correctly.
  encapsulationTrap: [7..7] = SIZE[Encapsulation];

  -- EthernetOne magic host numbers
  ethernetOneBroadcastHost: Byte = 0;
  ethernetOnePeekHost: Byte = 376B; -- DMT error info
  ethernetOneBootLoaderHost: Byte = 377B;

  -- Ethernet() magic host numbers
  ethernetBroadcastHost: HostNumber = SpecialSystem.broadcastHostNumber;

  -- offsets are in words
  localEncapsulationOffset: CARDINAL = 5;
  localEncapsulationBytes: CARDINAL = 4;
  ethernetEncapsulationOffset: CARDINAL = 5;
  ethernetEncapsulationBytes: CARDINAL = 4;
  slaEncapsulationOffset: CARDINAL = 6;
  slaEncapsulationBytes: CARDINAL = 2;
  prEncapsulationOffset: CARDINAL = 7;
  prEncapsulationBytes: CARDINAL = 0;
  prEncapsulationWords: CARDINAL = prEncapsulationBytes/2;
  phoneEncapsulationOffset: CARDINAL = 3;
  phoneEncapsulationBytes: CARDINAL = 8;

  LocalPacketType: TYPE = MACHINE DEPENDENT{pup(1000B), ois(3000B), (LAST[WORD])};

  EthernetPacketType: TYPE = MACHINE DEPENDENT{
    echoMe(700B), echoed(701B), pup(1000B), translation(1001B), ois(3000B), (LAST[
    WORD])};

  EthernetOnePacketType: TYPE = MACHINE DEPENDENT{
    peekData(402B), breathOfLife(602B), echoMe(700B), echoed(701B), pup(1000B),
    ois(3000B), translation(3001B), (LAST[WORD])};

  SlaPacketType: TYPE = MACHINE DEPENDENT{
    debugging(700B), pup(1000B), routing(1001B), password(1002B), ois(3000B),
    (LAST[WORD])};

  ArpanetLink: TYPE = MACHINE DEPENDENT{pup(152), (LAST[Byte])};

  PRPacketType: TYPE = MACHINE DEPENDENT{
    pup(1), ois(2), imAlive(3), broadcastPup(4), (LAST[Nibble])};

  PhonePacketType: TYPE = MACHINE DEPENDENT{
    pupPhonePacket(100B), oisPhonePacket(300B), turnAroundPhonePacket(301B),
    turnAroundMTSPhonePacket(302B), (LAST[Byte])};


  -- DEBUGGING

  Seal: TYPE = RECORD [WORD];
  unsealed: Seal = [0];
  queueSeal: Seal = [123001B];
  bufferSeal: Seal = [123002B];
  bufferPoolSeal: Seal = [123003B];

  END.