ARP using TINA

Jeroen.Vandezande
 
Avatar
 
Subject:

ARP using TINA

 · 
Posted: 24.02.2011 - 20:52  ·  #1
Hi,

I am looking into using TINA for a next project and I have seen that someone made a DHCP unit.
I was also planning to use a system when DHCP fails, that system is implemented in all PC operating systems and it is not complicated to implement in an MCU aswell.
But you need to be able to send ARP packets to get this working...
Is this possible with TINA, and if not is it planned to allow creation of ARP packets?

Best Regards,

Jeroen Vandezande
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: ARP using TINA

 · 
Posted: 24.02.2011 - 21:11  ·  #2
Hello Jeroen,

there is a such a function in the TINA core:
function RequestARP(QuestIP : tIPaddr; Var ReturnMAC : TMacAddr) : Boolean;
It is used in TINA_Ping for example. But I don't know if it fits for your needs.

rolf
Jeroen.Vandezande
 
Avatar
 
Subject:

Re: ARP using TINA

 · 
Posted: 25.02.2011 - 10:19  ·  #3
Hi,

I was thinking of implementing this RFC:
Dynamic Configuration of IPv4 Link-Local Addresses

What is does is this:

When no address can be obtained from DHCP you pick a random address from this range:
169.254.1.0 to 169.254.254.255

This range has been cleared by IATA for this purpose.

Then you have to do an ARP Probe :
Quote
A host probes to see if an address is already in use by broadcasting
an ARP Request for the desired address. The client MUST fill in the
'sender hardware address' field of the ARP Request with the hardware
address of the interface through which it is sending the packet. The
'sender IP address' field MUST be set to all zeroes, to avoid
polluting ARP caches in other hosts on the same link in the case
where the address turns out to be already in use by another host.
The 'target hardware address' field is ignored and SHOULD be set to
all zeroes. The 'target IP address' field MUST be set to the address
being probed. An ARP Request constructed this way with an all-zero
'sender IP address' is referred to as an "ARP Probe".


I am not sure that the ARP command from the TINA stack can do this...
I can't find more info about it in the Manual...

Best Regards,

Jeroen Vandezande
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: ARP using TINA

 · 
Posted: 25.02.2011 - 19:41  ·  #4
Hello Jeroen,

sorry, I can't help you. The only ARP handling in the TINA driver is this:
Code
Procedure BuildARPHeader(TargetIP : tIPaddr);
Begin
  OSI_ARP.HardwareType        := SWAP(1);
  OSI_ARP.ProtocolType        := SWAP(2048);
  OSI_ARP.HardwareAdrLen      := 6;
  OSI_ARP.ProtocolAdrLen      := 4;
  OSI_ARP.Operation           := SWAP(1);
  OSI_ARP.SenderHardwareAdr   := iLocalMacAdr;
  OSI_ARP.SenderIPAdr         := iLocalIPAdr;
  OSI_ARP.TargetHardwareAdr[0]:= $FF; //Alles $FF da Broadcast
  OSI_ARP.TargetHardwareAdr[1]:= $FF;
  OSI_ARP.TargetHardwareAdr[2]:= $FF;
  OSI_ARP.TargetHardwareAdr[3]:= $FF;
  OSI_ARP.TargetHardwareAdr[4]:= $FF;
  OSI_ARP.TargetHardwareAdr[5]:= $FF;
  OSI_ARP.TargetIPAdr         := TargetIP;
end;

function  RequestARP(QuestIP : tIPaddr; Var ReturnMAC : TMacAddr) : Boolean;
Var
    DEA                     : TMacAddr;
    TempIP                  : tIPaddr;
    i                       : Byte;
    Mask                    : tIPaddr;
Begin
  Mask[0]:= 255;
  Mask[1]:= 255;
  Mask[2]:= 255;
  Mask[3]:= 0;
  FillBlock(@DEA, 6, $FF); //Broadcast generieren
  for i:= 1 to ARP_Retry do
    //Vergleiche Netze und Suche dann Im ARP-Cache, ob MAC zur IP passt !
    if CompareNet( QuestIP, iLocalIPAdr, Mask) then //Meine und die Zieladresse liegen im gleichen Netz
      if CompareARPCache(QuestIP, ReturnMAC) then
        Return(TRUE);
      endif;
      BuildARPHeader(QuestIP);
      BuildEthernetHeader($806, DEA, Sizeof(TOSI_ARP));
      TempIP:= QuestIP;
    Else
      //Meine und die Zieladresse liegen NICHT! im gleichen Netz; also frage hier das DefaultGateway !
      if CompareARPCache(DefaultGateway, ReturnMAC) then
        Return(TRUE);
      endif;
      BuildARPHeader(DefaultGateway);
      BuildEthernetHeader($806, DEA, Sizeof(TOSI_ARP));
      TempIP:= DefaultGateway;
    endif;

    if SendOutPacket(@OSI_ARP, Sizeof(TOSI_ARP)) then
      SetSystimer(ReqTOTimer, ARP_Timeout);
      Repeat
        if TINA_DRV_PacketReceived then
          if TINA_DRV_ReceivePacket(@iNetBuf, Sizeof(iNetBuf)) = 0 then
            break;
          endif;
          if ((SWAP(OSI_ARP.Operation) = $02) and (OSI_ARP.TargetIPAdr = iLocalIPAdr)) then
            ARPCacheAdd(OSI_ARP.SenderIPAdr, OSI_ARP.SenderHardwareAdr);
            ReturnMAC:= OSI_ARP.SenderHardwareAdr;
            Return(TRUE);
          Else
            break;
          endif;
        endif;
      Until isSystimerZero(ReqTOTimer);
    endif;
  endfor;
  Return(False);
end;

rolf
Jeroen.Vandezande
 
Avatar
 
Subject:

Re: ARP using TINA

 · 
Posted: 25.02.2011 - 20:51  ·  #5
Hi,

The function "SendOutPacket(@OSI_ARP, Sizeof(TOSI_ARP))"
Can we call it also? or is it shielded?
What would be great is that TINA would also allow IP-Raw as protocol mode.
Then we could make our own ARP packets etc...

I noticed that TINA is included as a PCU file. Is it also available as .pas files?

Because then I could try to add it myself...


Best Regards,

Jeroen
Jeroen.Vandezande
 
Avatar
 
Subject:

Re: ARP using TINA

 · 
Posted: 01.03.2011 - 13:50  ·  #6
Hmm,

It seems that I have re implement the full ENC28J60 IC all over again in AVRCO.
It's a pity that we can't have ARP in Tina though because I would think that ZeroConfiguration is something that everybody would love to have on it's device. That is keeping me from going to ethernet at this momen: my end users don't know what an IP adress is, they just want to plug in the device and it should work, the problem is that a DHCP server is not always there.
Now I just found out that there is a way to auto-assign IP addresses for small local lans.
But you need ARP to get that working...

Aside from doing the Tina work all over again for the ENC28J80, I could use someniong like those Digi Connect things.


Best Regards,

Jeroen
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   107   121 · Page-Gen-Time: 0.028097s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI