■ SNIFFERSHOT 1. If you set your
breakpoints carefully, you can see
this TCP packet embedded within
the PIC’s SRAM. The SYN flag is
considered a byte of data in this
still, and fetches PawPaw’s
refreshment. After a few minutes,
PawPaw’s jug is renewed.
In this case, PawPaw established a communications session
with Bubba. Once the communications session was established,
Bubba made sure that he understood PawPaw correctly and
proceeded to carry out PawPaw’s
command. The communication
session between PawPaw and
Bubba officially ended when
Bubba delivered the jug of shine.
Bubba, his job done, went back to the barn to finish
feeding the hogs. This is how TCP works.
FETCHING “SHINE” WITH A PIC
Let’s replace PawPaw with a laptop running Telnet and
Bubba with a PIC running a miniature TCP application.
Instead of fetching moonshine, our goal will be to receive
an echo of every character we send from the laptop client
to the PIC server. We already have the hardware in place in
the form of the EDTP Ethernet MINI. So, all we need to do
is to tap out some TCP driver code. Up to this point, we’ve
been using PICBASIC PRO. This time around, we’ll still
employ the services of PICBASIC PRO but instead of using
the 16 bit version, we’ll upgrade to the new 32 bit version
of PICBASIC PRO, which is invoked by calling the PBPL
executable. Our new spin of TCP code requires the
manipulation of 32 bit values and thanks to PBPL, we won’t
have to code up any “ 32 bit
fake-out” routines, which will
also make the new TCP code set
easier for you to follow.
We will not be modifying any
of the code we’ve written thus far.
The TCP module will be an
addition to the code we have
already produced. Incoming
Ethernet frames will be handled
just as they were before.
However, now we will branch to a
real TCP code module rather than
just perform the gosub to an empty TCP subroutine that
right now only contains a single return instruction.
The recent addition of a PICBASIC PRO DHCP module
to our EDTP Ethernet MINI driver eliminates the need to
hardcode an EDTP Ethernet MINI IP address. However, like
UDP, TCP requires us to define at least one port address.
We must leave our old port address buddy 8088 behind as
the new version of the Network General Sniffer Portable
automatically identifies our old port address value of 8088
decimal with an HTTP component. Rather than disable this
very nice feature of Sniffer Portable, I simply assigned
20202 decimal ($4EEA hexadecimal) as our new local TCP
TCP session establishment depends on keeping up
with some 32 bit numbers and a set of TCP flags. PBPL
has the 32 bit job covered and the flag recognition and
manipulation activities are left to us. Here’s how we define
the TCP flags:
■ SNIFFERSHOT 2. Three
major events occur in the second
handshake. The incoming SYN is
acknowledged, the EDTP Ethernet
MINI sends its initial sequence
number, and the SYN and ACK flags
are set in the outgoing packet.
December 2007 77