I would be very grateful if anyone can help me check the code below and make
it run.
/************************** 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){}
/*******************************************************/
}
--
View this message in context:
http://tinyos-help.10906.n7.nabble.com/Can-I-get-rid-of-IPBasesation-and-send-tcp-packets-between-two-motes-tp23239p23246.html
Sent from the TinyOS - Help mailing list archive at Nabble.com.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help