00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00058 #define UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS 0
00059 #endif // ifndef UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00060
00061 #ifndef UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
00062 #define UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR 1
00063 #endif // ifndef UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
00064
00065 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 #else
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 #endif
00225
00226 #include "uip.h"
00227 #include "uip_arp.h"
00228
00229 #include "net/rime.h"
00230 #include "sicslowpan.h"
00231 #include "sicslow_ethernet.h"
00232 #if !RF230BB
00233 #include "zmac.h"
00234 #include "frame.h"
00235 #include "radio.h"
00236 #endif
00237 #include "rndis/rndis_protocol.h"
00238 #include "rndis/rndis_task.h"
00239
00240 #include <stdint.h>
00241 #include <stdio.h>
00242 #include <string.h>
00243
00244 #define DEBUG 0
00245 #if DEBUG
00246 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
00247 #else
00248 #define PRINTF(...)
00249 #endif
00250
00251 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
00252 #define ETHBUF(x) ((struct uip_eth_hdr *)x)
00253
00254
00255 #ifndef LSB
00256 #define LSB(u16) (((uint8_t *)&(u16))[0])
00257 #define MSB(u16) (((uint8_t *)&(u16))[1])
00258 #endif
00259
00260 static const uint64_t simple_trans_ethernet_addr = 0x3E3D3C3B3AF2ULL;
00261
00262 #if UIP_CONF_IPV6_RPL
00263 static uip_ipaddr_t last_sender;
00264 #endif
00265
00266 extern uint64_t usb_ethernet_addr;
00267
00268 extern uint64_t macLongAddr;
00269
00270 #if !RF230BB
00271 extern void (*pinput)(const struct mac_driver *r);
00272 void (*sicslowinput)(const struct mac_driver *r);
00273 parsed_frame_t * parsed_frame;
00274 #endif
00275 usbstick_mode_t usbstick_mode;
00276
00277 uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan);
00278 uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan);
00279 uint8_t mac_createDefaultEthernetAddr(uint8_t * ethernet);
00280 void mac_ethhijack_nondata(const struct mac_driver *r);
00281 void mac_ethhijack(const struct mac_driver *r);
00282
00283 extern void (*sicslowmac_snifferhook)(const struct mac_driver *r);
00284
00285
00286
00287 #define TRANSLATE_BIT_MASK (1<<2)
00288
00289 #define LOCAL_BIT_MASK (1<<1)
00290
00291 #define MULTICAST_BIT_MASK (1<<0)
00292
00293 #define PREFIX_BUFFER_SIZE 32
00294
00295 uint8_t prefixCounter;
00296 uint8_t prefixBuffer[PREFIX_BUFFER_SIZE][3];
00297
00298
00299 uint8_t raw_buf[127+ UIP_LLH_LEN +1];
00300
00301
00302
00303
00304 #if !RF230BB
00305 struct mac_driver * pmac;
00306 #endif
00307 void mac_ethernetSetup(void)
00308 {
00309 usbstick_mode.sicslowpan = 1;
00310 usbstick_mode.sendToRf = 1;
00311 usbstick_mode.translate = 1;
00312 usbstick_mode.debugOn= 1;
00313 usbstick_mode.raw = 0;
00314 usbstick_mode.sneeze=0;
00315
00316 #if !RF230BB
00317 sicslowinput = pinput;
00318
00319 pmac = sicslowmac_get_driver();
00320 pmac->set_receive_function(mac_ethhijack);
00321 sicslowmac_snifferhook = mac_ethhijack_nondata;
00322 #endif
00323 }
00324
00325
00326
00327
00328
00329
00330 void mac_ethernetToLowpan(uint8_t * ethHeader)
00331 {
00332
00333 uip_lladdr_t destAddr;
00334 uip_lladdr_t *destAddrPtr = NULL;
00335
00336 PRINTF("Packet type: 0x%04x\n\r", uip_ntohs(((struct uip_eth_hdr *) ethHeader)->type));
00337
00338
00339 #if UIP_CONF_USE_RUM
00340 return;
00341 #endif
00342
00343
00344 if ((usbstick_mode.sendToRf == 0) || (usbstick_mode.sneeze != 0)) {
00345 uip_len = 0;
00346 return;
00347 }
00348
00349
00350
00351 if (((struct uip_eth_hdr *) ethHeader)->type != UIP_HTONS(UIP_ETHTYPE_IPV6)) {
00352 PRINTF("eth2low: Dropping packet w/type=0x%04x\n",uip_ntohs(((struct uip_eth_hdr *) ethHeader)->type));
00353
00354 #if !RF230BB
00355 usb_eth_stat.txbad++;
00356 #endif
00357 uip_len = 0;
00358 return;
00359 }
00360
00361
00362 if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0x33) &&
00363 (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0x33) )
00364 {
00365 PRINTF("eth2low: Ethernet multicast packet received\n\r");
00366 ;
00367 } else if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0xFF) &&
00368 (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0xFF) &&
00369 (((struct uip_eth_hdr *) ethHeader)->dest.addr[2] == 0xFF) &&
00370 (((struct uip_eth_hdr *) ethHeader)->dest.addr[3] == 0xFF) &&
00371 (((struct uip_eth_hdr *) ethHeader)->dest.addr[4] == 0xFF) &&
00372 (((struct uip_eth_hdr *) ethHeader)->dest.addr[5] == 0xFF) ) {
00373
00374 PRINTF("eth2low: Dropping broadcast packet\n\r");
00375 #if !RF230BB
00376 usb_eth_stat.txbad++;
00377 #endif
00378 uip_len = 0;
00379 return;
00380 } else {
00381
00382
00383 if(memcmp((uint8_t *)&simple_trans_ethernet_addr, &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), 6) == 0) {
00384 #if UIP_CONF_IPV6
00385
00386 destAddr.addr[0] = UIP_IP_BUF->destipaddr.u8[8] ^ 0x02;
00387 destAddr.addr[1] = UIP_IP_BUF->destipaddr.u8[9];
00388 destAddr.addr[2] = UIP_IP_BUF->destipaddr.u8[10];
00389 destAddr.addr[3] = UIP_IP_BUF->destipaddr.u8[11];
00390 destAddr.addr[4] = UIP_IP_BUF->destipaddr.u8[12];
00391 destAddr.addr[5] = UIP_IP_BUF->destipaddr.u8[13];
00392 destAddr.addr[6] = UIP_IP_BUF->destipaddr.u8[14];
00393 destAddr.addr[7] = UIP_IP_BUF->destipaddr.u8[15];
00394 #else
00395
00396 destAddr.addr[0] = UIP_IP_BUF->destipaddr.u8[0] ^ 0x02;
00397 destAddr.addr[1] = UIP_IP_BUF->destipaddr.u8[1];
00398 destAddr.addr[2] = UIP_IP_BUF->destipaddr.u8[2];
00399 destAddr.addr[3] = UIP_IP_BUF->destipaddr.u8[3];
00400 destAddr.addr[4] = UIP_IP_BUF->destipaddr.u8[0];
00401 destAddr.addr[5] = UIP_IP_BUF->destipaddr.u8[1];
00402 destAddr.addr[6] = UIP_IP_BUF->destipaddr.u8[2];
00403 destAddr.addr[7] = UIP_IP_BUF->destipaddr.u8[3];
00404
00405 #endif
00406
00407 destAddrPtr = &destAddr;
00408 }
00409 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00410 else {
00411
00412 uip_len = 0;
00413 return;
00414 }
00415 #else
00416
00417
00418 PRINTF("eth2low: Addressed packet received... ");
00419
00420 if (mac_createSicslowpanLongAddr( &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), &destAddr) == 0) {
00421 PRINTF(" translation failed\n\r");
00422 #if !RF230BB
00423 usb_eth_stat.txbad++;
00424 #endif
00425 uip_len = 0;
00426 return;
00427 }
00428 PRINTF(" translated OK\n\r");
00429 destAddrPtr = &destAddr;
00430 #endif
00431
00432
00433 }
00434
00435
00436 uip_len -= UIP_LLH_LEN;
00437
00438
00439 if (usbstick_mode.translate) {
00440 #if DEBUG
00441 uint8_t transReturn = mac_translateIPLinkLayer(ll_802154_type);
00442 PRINTF("IPTranslation: returns %d\n\r", transReturn);
00443 #else
00444 mac_translateIPLinkLayer(ll_802154_type);
00445 #endif
00446 }
00447
00448 #if UIP_CONF_IPV6
00449
00450 #if UIP_CONF_IPV6_RPL
00451
00452 uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr);
00453 tcpip_input();
00454 #else
00455
00456
00457 tcpip_output(destAddrPtr);
00458 #endif
00459 #else
00460 tcpip_output();
00461 #endif
00462
00463 #if !RF230BB
00464 usb_eth_stat.txok++;
00465 #endif
00466 uip_len = 0;
00467
00468 }
00469
00470
00471
00472
00473
00474
00475 void mac_LowpanToEthernet(void)
00476 {
00477 #if !RF230BB
00478 parsed_frame = sicslowmac_get_frame();
00479 #endif
00480
00481
00482 ETHBUF(uip_buf)->type = uip_htons(UIP_ETHTYPE_IPV6);
00483
00484
00485
00486 #if RF230BB
00487 if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
00488
00489 #else
00490 if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) &&
00491 ( parsed_frame->dest_addr->addr16 == 0xffff) ) {
00492 #endif
00493 ETHBUF(uip_buf)->dest.addr[0] = 0x33;
00494 ETHBUF(uip_buf)->dest.addr[1] = 0x33;
00495
00496 #if UIP_CONF_IPV6
00497 ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
00498 ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
00499 ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
00500 ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
00501 #else
00502
00503 ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[0];
00504 ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[1];
00505 ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[2];
00506 ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[3];
00507 #endif
00508 } else {
00509
00510 mac_createEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->dest.addr[0]),
00511 (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
00512 }
00513
00514 #if !UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00515
00516 if(!mac_createEthernetAddr(
00517 (uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]),
00518 (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)
00519 ))
00520 #endif
00521
00522 {
00523 mac_createDefaultEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]));
00524 }
00525
00526
00527 if (usbstick_mode.translate) {
00528
00529 mac_translateIPLinkLayer(ll_8023_type);
00530 }
00531
00532 #if UIP_CONF_IPV6_RPL
00533
00534 if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
00535 PRINTF("siclow_ethernet: Destination off-link but no route\n");
00536 uip_len=0;
00537 return;
00538 }
00539 #endif
00540
00541 PRINTF("Low2Eth: Sending packet to ethernet\n\r");
00542
00543 uip_len += UIP_LLH_LEN;
00544
00545 usb_eth_send(uip_buf, uip_len, 1);
00546 #if !RF230BB
00547 usb_eth_stat.rxok++;
00548 #endif
00549 uip_len = 0;
00550 }
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563 int8_t mac_translateIPLinkLayer(lltype_t target)
00564 {
00565
00566 #if UIP_LLADDR_LEN == 8
00567 if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) {
00568 PRINTF("eth2low: ICMP Message detected\n\r");
00569 return mac_translateIcmpLinkLayer(target);
00570 }
00571 return 0;
00572 #else
00573 return 1;
00574 #endif
00575
00576 }
00577
00578 #include "net/uip-icmp6.h"
00579 #include "net/uip-nd6.h"
00580
00581 typedef struct {
00582 uint8_t type;
00583 uint8_t length;
00584 uint8_t data[16];
00585 } icmp_opts_t;
00586
00587 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
00588 #define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x])
00589
00590 void slide(uint8_t * data, uint8_t length, int16_t slide);
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603 int8_t mac_translateIcmpLinkLayer(lltype_t target)
00604 {
00605 uint16_t icmp_opt_offset = 0;
00606 int16_t len = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0] << 8);
00607
00608 uint16_t iplen;
00609
00610 uint8_t i;
00611
00612 int16_t sizechange;
00613
00614 uint8_t llbuf[16];
00615
00616
00617 switch(UIP_ICMP_BUF->type) {
00618 case ICMP6_NS:
00619 case ICMP6_NA:
00620 icmp_opt_offset = 24;
00621 break;
00622
00623 case ICMP6_RS:
00624 icmp_opt_offset = 8;
00625 break;
00626
00627 case ICMP6_RA:
00628 icmp_opt_offset = 16;
00629 break;
00630
00631 case ICMP6_REDIRECT:
00632 icmp_opt_offset = 40;
00633 break;
00634
00635
00636 case ICMP6_DST_UNREACH:
00637 case ICMP6_PACKET_TOO_BIG:
00638 case ICMP6_TIME_EXCEEDED:
00639 case ICMP6_PARAM_PROB:
00640 case ICMP6_ECHO_REQUEST:
00641 case ICMP6_ECHO_REPLY:
00642 return 0;
00643 break;
00644
00645 default:
00646 return -1;
00647 }
00648
00649
00650 len -= icmp_opt_offset;
00651
00652
00653 if (len < 8) return -2;
00654
00655
00656 while (len >= 8){
00657
00658
00659 if (((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_SLLAO) ||
00660 ((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_TLLAO) ) {
00661
00662
00663
00664 for(i = 0; i < (UIP_ICMP_OPTS(icmp_opt_offset)->length*8 - 2); i++) {
00665 llbuf[i] = UIP_ICMP_OPTS(icmp_opt_offset)->data[i];
00666 }
00667
00668
00669 if (target == ll_802154_type) {
00670
00671 sizechange = 8;
00672 slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 6, len - 6, sizechange);
00673 } else if (target == ll_8023_type) {
00674
00675
00676
00677
00678
00679
00680 sizechange = -8;
00681 slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 14, len - 14, sizechange);
00682 } else {
00683 return -3;
00684 }
00685
00686
00687 if (target == ll_802154_type) {
00688 mac_createSicslowpanLongAddr(llbuf, (uip_lladdr_t *)UIP_ICMP_OPTS(icmp_opt_offset)->data);
00689 } else {
00690 #if !UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00691 if(!mac_createEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data, (uip_lladdr_t *)llbuf))
00692 #endif
00693 mac_createDefaultEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data);
00694 }
00695
00696
00697 if (target == ll_802154_type) {
00698 UIP_ICMP_OPTS(icmp_opt_offset)->length = 2;
00699 } else {
00700 UIP_ICMP_OPTS(icmp_opt_offset)->length = 1;
00701 }
00702
00703
00704 iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0]<<8);
00705 iplen += sizechange;
00706 len += sizechange;
00707
00708 UIP_IP_BUF->len[1] = (uint8_t)iplen;
00709 UIP_IP_BUF->len[0] = (uint8_t)(iplen >> 8);
00710
00711 uip_len += sizechange;
00712
00713
00714 UIP_ICMP_BUF->icmpchksum = 0;
00715 #if UIP_CONF_IPV6 //allow non ipv6 builds
00716 UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
00717 #endif
00718
00719
00720 len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
00721 icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
00722 } else {
00723
00724
00725 len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
00726
00727
00728 if (UIP_ICMP_OPTS(icmp_opt_offset)->length == 0) {
00729 PRINTF("Option in ND packet has length zero, error?\n\r");
00730 len = 0;
00731 }
00732
00733 icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
00734
00735 }
00736
00737 }
00738
00739 return 0;
00740
00741 }
00742
00743
00744
00745
00746
00747
00748
00749 uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
00750 {
00751 #if UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
00752
00753
00754 if (memcmp((uint8_t *)&usb_ethernet_addr, ethernet, 6) == 0)
00755 {
00756 memcpy((uint8_t *)lowpan, &macLongAddr, UIP_LLADDR_LEN);
00757 return 1;
00758 }
00759 #endif
00760
00761 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00762
00763
00764 lowpan->addr[0] = ethernet[0];
00765 lowpan->addr[1] = ethernet[1];
00766 lowpan->addr[2] = ethernet[2];
00767 lowpan->addr[3] = 0xff;
00768 lowpan->addr[4] = 0xfe;
00769 lowpan->addr[5] = ethernet[3];
00770 lowpan->addr[6] = ethernet[4];
00771 lowpan->addr[7] = ethernet[5];
00772
00773 #else
00774
00775 uint8_t index;
00776
00777 #if UIP_LLADDR_LEN == 8
00778
00779 if((ethernet[0]&(TRANSLATE_BIT_MASK|MULTICAST_BIT_MASK|LOCAL_BIT_MASK)) == (TRANSLATE_BIT_MASK|LOCAL_BIT_MASK)) {
00780
00781 index = ethernet[0] >> 3;
00782
00783
00784 lowpan->addr[0] = prefixBuffer[index][0];
00785 lowpan->addr[1] = prefixBuffer[index][1];
00786 lowpan->addr[2] = prefixBuffer[index][2];
00787 lowpan->addr[3] = ethernet[1];
00788 lowpan->addr[4] = ethernet[2];
00789
00790
00791 if (index >= prefixCounter)
00792 return 0;
00793 } else {
00794 lowpan->addr[0] = ethernet[0];
00795 lowpan->addr[1] = ethernet[1];
00796 lowpan->addr[2] = ethernet[2];
00797 lowpan->addr[3] = 0xff;
00798 lowpan->addr[4] = 0xfe;
00799 }
00800
00801 lowpan->addr[5] = ethernet[3];
00802 lowpan->addr[6] = ethernet[4];
00803 lowpan->addr[7] = ethernet[5];
00804
00805 #else //UIP_LLADDR != 8
00806
00807 uint8_t i;
00808 for(i = 0; i < UIP_LLADDR_LEN; i++) {
00809 lowpan->addr[i] = ethernet[i];
00810 }
00811 #endif //UIP_LLADDR == 8
00812
00813 #endif //UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00814
00815 return 1;
00816 }
00817
00818
00819
00820
00821
00822
00823
00824 uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
00825 {
00826 #if UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
00827
00828
00829 if (memcmp((uint8_t *)&macLongAddr, (uint8_t *)lowpan, UIP_LLADDR_LEN) == 0) {
00830 usb_eth_get_mac_address(ethernet);
00831 return 1;
00832 }
00833 #endif
00834
00835 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00836
00837
00838 ethernet[0] = lowpan->addr[0];
00839 ethernet[1] = lowpan->addr[1];
00840 ethernet[2] = lowpan->addr[2];
00841 ethernet[3] = lowpan->addr[5];
00842 ethernet[4] = lowpan->addr[6];
00843 ethernet[5] = lowpan->addr[7];
00844
00845 #else
00846
00847 uint8_t index = 0;
00848 uint8_t i;
00849
00850 #if UIP_LLADDR_LEN == 8
00851
00852
00853 if ((lowpan->addr[3] == 0xff) && (lowpan->addr[4] == 0xfe) &&
00854 ((lowpan->addr[0] & TRANSLATE_BIT_MASK) == 0) &&
00855 ((lowpan->addr[0] & MULTICAST_BIT_MASK) == 0) &&
00856 (lowpan->addr[0] & LOCAL_BIT_MASK)) {
00857
00858
00859 ethernet[0] = lowpan->addr[0];
00860 ethernet[1] = lowpan->addr[1];
00861 ethernet[2] = lowpan->addr[2];
00862 ethernet[3] = lowpan->addr[5];
00863 ethernet[4] = lowpan->addr[6];
00864 ethernet[5] = lowpan->addr[7];
00865
00866
00867 } else {
00868
00869
00870 for (i = 0; i < prefixCounter; i++) {
00871
00872 if ((lowpan->addr[0] == prefixBuffer[i][0]) &&
00873 (lowpan->addr[1] == prefixBuffer[i][1]) &&
00874 (lowpan->addr[2] == prefixBuffer[i][2])) {
00875 break;
00876 }
00877 }
00878 index = i;
00879
00880 if (index >= PREFIX_BUFFER_SIZE) {
00881
00882
00883 ethernet[0] = lowpan->addr[0];
00884 ethernet[1] = lowpan->addr[1];
00885 ethernet[2] = lowpan->addr[2];
00886 ethernet[3] = lowpan->addr[5];
00887 ethernet[4] = lowpan->addr[6];
00888 ethernet[5] = lowpan->addr[7];
00889 return 0;
00890 } else {
00891
00892 if (index == prefixCounter) {
00893 prefixCounter++;
00894 prefixBuffer[index][0] = lowpan->addr[0];
00895 prefixBuffer[index][1] = lowpan->addr[1];
00896 prefixBuffer[index][2] = lowpan->addr[2];
00897 }
00898
00899
00900 ethernet[0] = TRANSLATE_BIT_MASK | LOCAL_BIT_MASK | (index << 3);
00901 ethernet[1] = lowpan->addr[3];
00902 ethernet[2] = lowpan->addr[4];
00903 ethernet[3] = lowpan->addr[5];
00904 ethernet[4] = lowpan->addr[6];
00905 ethernet[5] = lowpan->addr[7];
00906 }
00907 }
00908
00909 #else //UIP_LLADDR_LEN != 8
00910
00911
00912 for(i = 0; i < UIP_LLADDR_LEN; i++) {
00913 ethernet[i] = lowpan->addr[i];
00914 }
00915 #endif //UIP_LLADDR_LEN == 8
00916
00917 #endif //UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
00918
00919 return 1;
00920 }
00921
00922
00923
00924
00925 uint8_t mac_createDefaultEthernetAddr(uint8_t * ethernet)
00926 {
00927 memcpy(ethernet, &simple_trans_ethernet_addr, 6);
00928 return 1;
00929 }
00930
00931
00932
00933
00934
00935
00936
00937
00938 void slide(uint8_t * data, uint8_t length, int16_t slide)
00939 {
00940
00941 if (!length) return;
00942 if (!slide) return;
00943
00944 uint8_t i = 0;
00945
00946 while(length) {
00947 length--;
00948
00949
00950 if (slide > 0) {
00951 *(data + length + slide) = *(data + length);
00952
00953
00954 } else {
00955 *(data + slide + i) = *(data + i);
00956 }
00957
00958 i++;
00959 }
00960 }
00961
00962
00963
00964
00965 void
00966 mac_log_802_15_4_tx(const uint8_t* buffer, size_t total_len) {
00967 if (usbstick_mode.raw != 0) {
00968 uint8_t sendlen;
00969
00970 static uint8_t raw_buf[127+ UIP_LLH_LEN +1];
00971
00972
00973 memcpy(&raw_buf[UIP_LLH_LEN], buffer, total_len);
00974 sendlen = total_len;
00975
00976
00977 ETHBUF(raw_buf)->type = uip_htons(0x809A);
00978
00979
00980 if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
00981 ETHBUF(raw_buf)->dest.addr[0] = 0x33;
00982 ETHBUF(raw_buf)->dest.addr[1] = 0x33;
00983 ETHBUF(raw_buf)->dest.addr[2] = 0x00;
00984 ETHBUF(raw_buf)->dest.addr[3] = 0x00;
00985 ETHBUF(raw_buf)->dest.addr[4] = 0x80;
00986 ETHBUF(raw_buf)->dest.addr[5] = 0x9A;
00987
00988
00989
00990
00991
00992
00993
00994 } else {
00995
00996 mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]),
00997 (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
00998 }
00999
01000
01001 mac_createDefaultEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]));
01002
01003 sendlen += UIP_LLH_LEN;
01004 usb_eth_send(raw_buf, sendlen, 0);
01005 }
01006 }
01007
01008 void
01009 mac_log_802_15_4_rx(const uint8_t* buf, size_t len) {
01010 if (usbstick_mode.raw != 0) {
01011 uint8_t sendlen;
01012
01013
01014 memcpy(&raw_buf[UIP_LLH_LEN], buf, len);
01015 sendlen = len;
01016
01017
01018 ETHBUF(raw_buf)->type = uip_htons(0x809A);
01019
01020
01021 if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
01022 ETHBUF(raw_buf)->dest.addr[0] = 0x33;
01023 ETHBUF(raw_buf)->dest.addr[1] = 0x33;
01024 ETHBUF(raw_buf)->dest.addr[2] = 0x00;
01025 ETHBUF(raw_buf)->dest.addr[3] = 0x00;
01026 ETHBUF(raw_buf)->dest.addr[4] = 0x80;
01027 ETHBUF(raw_buf)->dest.addr[5] = 0x9A;
01028
01029
01030
01031
01032
01033
01034 } else {
01035
01036 mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]),
01037 (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
01038 }
01039
01040
01041 mac_createDefaultEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]));
01042
01043 sendlen += UIP_LLH_LEN;
01044 usb_eth_send(raw_buf, sendlen, 0);
01045 }
01046 }
01047
01048 bool
01049 mac_is_send_enabled(void) {
01050 if ((usbstick_mode.sendToRf == 0) || (usbstick_mode.sneeze != 0)) return 0;
01051 return 1;
01052
01053 }
01054
01055
01056
01057
01058
01059
01060
01061
01062 #if !RF230BB
01063
01064
01065
01066
01067
01068
01069
01070 void mac_ethhijack(const struct mac_driver *r)
01071 {
01072 if (usbstick_mode.raw) {
01073 mac_802154raw(r);
01074 }
01075
01076 if (usbstick_mode.sicslowpan) {
01077
01078 #if UIP_CONF_USE_RUM
01079 if (parsed_frame->payload[4]) {
01080 #endif
01081 sicslowinput(r);
01082 #if UIP_CONF_USE_RUM
01083 }
01084 #endif
01085
01086
01087 }
01088
01089 }
01090
01091 void mac_ethhijack_nondata(const struct mac_driver *r)
01092 {
01093 if (usbstick_mode.raw)
01094 mac_802154raw(r);
01095 }
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105 void mac_logTXtoEthernet(frame_create_params_t *p,frame_result_t *frame_result)
01106 {
01107 mac_log_802_15_4_tx(frame_result->frame, frame_result->length);
01108 }
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118 void mac_802154raw(const struct mac_driver *r) {
01119 mac_log_802_15_4_tx(radio_frame_data(), radio_frame_length());
01120 }
01121
01122 #endif
01123
01124
01125