Hi,

I am currently working with TinyOS, especially with the BLIP stack and 
my aim is to establish a TCP-based communication between two TelosB 
motes. For this case I use one mote as a client and another one as a 
server. I tried to establish a connection between them, but without success.

Each mote obtains an IPv6 address according to stateless address 
autoconfiguration. Such an address consists of a link-local prefix 
(fe80::) and an interface identifier (8 byte MAC address).

If the client starts to connect, the server will execute its accept 
event. However, independend from the return value the connection will 
always be rejected. If FALSE is returned, the connection will be 
terminated immediately, if TRUE is returned the connection will also be 
terminated, but due to a timeout. And this is confusing for me. Is there 
anything that I have not considered?

The source code for the client and the server is attached. I would be 
grateful for any advice.

Regards,
Matthias Scheler



/************************** CLIENT WIRING **************************/

#include <6lowpan.h>

configuration TCPClientC {
} implementation {
   components MainC, LedsC;
   components TCPClientP;
   components IPAddressC;
   components IPDispatchC;
   components new TcpSocketC();

   TCPClientP.Boot -> MainC;
   TCPClientP.Leds -> LedsC;
   TCPClientP.IPAddress -> IPAddressC;
   TCPClientP.RadioControl -> IPDispatchC;
   TCPClientP.TCPSocket -> TcpSocketC;
}

/********************** CLIENT IMPLEMENTATION **********************/

#include <IPDispatch.h>
#include <lib6lowpan.h>
#include <ip.h>

module TCPClientP {
   uses {
     interface Boot;
     interface Tcp as TCPSocket;
     interface Leds;
     interface IPAddress;
     interface SplitControl as RadioControl;
   }

} implementation {
   #define myPort 7
   #define destPort 8
   #define myTcpBufLen 100

   char tcpBuf[myTcpBufLen];

   event void Boot.booted() {
     struct in6_addr *myAddress;
     struct sockaddr_in6 destAddress;

     call RadioControl.start();

     /** generate ipv6-address as follows
      * [link-local prefix : interface identifier]
      * -> link-local prefix:    fe80::
      * -> interface identifier: 8 byte mac address
      */
     myAddress = call IPAddress.getPublicAddr();
     inet_pton6("fe80::0012:7400:0e33:0392", myAddress);

     // set TOS_NODE_ID to the last 2 bytes of the mac address
     // this is necessary, since TOS_NODE_ID is used as short address
     call IPAddress.setShortAddr(0x0392);

     // set destination ip-address
     inet_pton6("fe80::0012:7400:0d69:5626", &destAddress.sin6_addr);
     // set destination port
     destAddress.sin6_port = htons(destPort);

     call TCPSocket.bind(myPort);
     call TCPSocket.connect(&destAddress, tcpBuf, myTcpBufLen);

     call Leds.set(1);
   }

   event void TCPSocket.connectDone(error_t e) {
     call Leds.set(2);
   }

   event void TCPSocket.closed(error_t e) {
     call Leds.set(4);
     call TCPSocket.bind(myPort);
   }

   event bool TCPSocket.accept(struct sockaddr_in6 *from,
                               void **tx_buf, int *tx_buf_len) {
     // client rejects any connections
     return FALSE;
   }

   /***************** NOT YET IMPLEMENTED *****************/

   event void TCPSocket.recv(void *payload, uint16_t len) {}

   event void TCPSocket.acked() {}

   event void RadioControl.startDone(error_t e) {}

   event void RadioControl.stopDone(error_t e) {}

   /*******************************************************/
}


/************************** SERVER WIRING **************************/

#include <6lowpan.h>

configuration TCPServerC {
} implementation {
   components MainC, LedsC;
   components TCPServerP;
   components IPAddressC;
   components IPDispatchC;
   components new TcpSocketC();

   TCPServerP.Boot -> MainC;
   TCPServerP.Leds -> LedsC;
   TCPServerP.IPAddress -> IPAddressC;
   TCPServerP.RadioControl -> IPDispatchC;
   TCPServerP.TCPSocket -> TcpSocketC;
}

/********************** SERVER IMPLEMENTATION **********************/

#include <IPDispatch.h>
#include <lib6lowpan.h>
#include <ip.h>

module TCPServerP {
   uses {
     interface Boot;
     interface Tcp as TCPSocket;
     interface Leds;
     interface IPAddress;
     interface SplitControl as RadioControl;
   }
} implementation {
   #define myPort 8
   #define myTcpBufLen 100

   char tcpBuf[myTcpBufLen];

   event void Boot.booted() {
     struct in6_addr *myAddress;

     call RadioControl.start();

     /** generate ipv6-address as follows
      * [link-local prefix : interface identifier]
      * -> link-local prefix:    fe80::
      * -> interface identifier: 8 byte mac address
      */
     myAddress = call IPAddress.getPublicAddr();
     inet_pton6("fe80::0012:7400:0d69:5626", myAddress);

     // set TOS_NODE_ID to the last 2 bytes of the mac address
     // this is necessary, since TOS_NODE_ID is used as short address
     call IPAddress.setShortAddr(0x5626);

     call TCPSocket.bind(myPort);
     call Leds.set(1);
   }

   event bool TCPSocket.accept(struct sockaddr_in6 *from,
                               void **tx_buf, int *tx_buf_len) {
     *tx_buf = tcpBuf;
     *tx_buf_len = myTcpBufLen;

     call Leds.set(2);

     // accept incoming connection
     return TRUE;
   }

   event void TCPSocket.closed(error_t e) {
     call Leds.set(4);
     call TCPSocket.bind(myPort);
   }

   /***************** NOT YET IMPLEMENTED *****************/

   event void TCPSocket.acked() {}

   event void TCPSocket.connectDone(error_t e) {}

   event void TCPSocket.recv(void *payload, uint16_t len) {}

   event void RadioControl.startDone(error_t e){}

   event void RadioControl.stopDone(error_t e){}

   /*******************************************************/
}

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to