struct pico_device *pico_vde_create(char *sock, char *name, uint8_t *mac) { struct pico_device_vde *vde = PICO_ZALLOC(sizeof(struct pico_device_vde)); struct vde_open_args open_args = { .mode = 0700 }; char vdename[] = "picotcp"; if (!vde) return NULL; if( 0 != pico_device_init((struct pico_device *)vde, name, mac)) { dbg ("Vde init failed.\n"); pico_vde_destroy((struct pico_device *)vde); return NULL; } vde->dev.overhead = 0; vde->sock = PICO_ZALLOC(strlen(sock) + 1); memcpy(vde->sock, sock, strlen(sock)); vde->conn = vde_open(sock, vdename, &open_args); if (!vde->conn) { pico_vde_destroy((struct pico_device *)vde); return NULL; } vde->dev.send = pico_vde_send; vde->dev.poll = pico_vde_poll; vde->dev.destroy = pico_vde_destroy; //printf("Device %s created.\n", vde->dev.name); return (struct pico_device *)vde; }
END_TEST START_TEST(tc_pico_sntp_parse) { /* TODO: test this: static void pico_sntp_parse(char *buf, struct sntp_server_ns_cookie *ck) */ struct sntp_server_ns_cookie *ck; struct pico_socket *sock; struct pico_sntp_header header = { 0 }; ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); fail_unless (ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); fail_unless (ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; sock = pico_socket_open(0, 0, &pico_sntp_client_wakeup); ck->sock = sock; sock->priv = ck; header.mode = 4; /* server mode */ header.vn = 4; /* sntp version 4 */ header.stratum = 1; /* primary reference */ header.trs_ts.sec = long_be(SNTP_UNIX_OFFSET + 1390000000ul); header.trs_ts.frac = long_be(3865470566ul); /* value: 899msec */ fail_if(pico_sntp_parse((char *) &header, NULL) == 0); fail_if(pico_sntp_parse((char *) &header, ck) != 0); }
END_TEST START_TEST(tc_pico_mld_timer_expired) { struct mld_timer *t,*s; t = PICO_ZALLOC(sizeof(struct mld_timer)); t->stopped = MLD_TIMER_STOPPED; t->type = 0; pico_string_to_ipv6("AAAA::1", t->mcast_link.addr); pico_string_to_ipv6("AAAA::1", t->mcast_group.addr); //void function, just check for side effects pico_mld_timer_expired(NULL, (void *)t); pico_tree_insert(&MLDTimers, t); s = PICO_ZALLOC(sizeof(struct mld_timer)); memcpy(s,t,sizeof(struct mld_timer)); // t will be freed next test pico_mld_timer_expired(NULL, (void *)t); /* will be freed */ s->stopped++; s->start = PICO_TIME_MS()*2; s->type++; pico_tree_insert(&MLDTimers, s); t = PICO_ZALLOC(sizeof(struct mld_timer)); memcpy(t,s,sizeof(struct mld_timer)); // s will be freed next test pico_mld_timer_expired(NULL, (void *)s); /* s will be freed */ t->mld_callback = mock_callback; pico_mld_timer_expired(NULL, (void *)t); /* t will be freed */ }
/* Sets up the generator, loading the seed from persistent storage if possible*/ int pico_rand_init(void) { int i = 0; pico_rand_generator.key = PICO_ZALLOC(sizeof(uint8_t) * PICO_RAND_ENCRYPT_KEY_SIZE); pico_rand_generator.pool = PICO_ZALLOC(sizeof(Sha256) * PICO_RAND_POOL_COUNT); /* n pools of strings; in practice, hashes iteratively updated */ pico_rand_generator.counter = PICO_ZALLOC(sizeof(struct pico_rand_counter_fortuna)); pico_rand_generator.aes = PICO_ZALLOC(sizeof(Aes)); pico_rand_generator.sha = PICO_ZALLOC(sizeof(Sha256)); if (NULL == pico_rand_generator.key || NULL == pico_rand_generator.pool || NULL == pico_rand_generator.aes || NULL == pico_rand_generator.sha) { return -1; /* Failed to allocate memory! */ } /* Set counter to 0 (also indicates unseeded state) */ pico_rand_init_counter (pico_rand_generator.counter); for (i = 0; i < PICO_RAND_POOL_COUNT; i++) { wc_InitSha256(&(pico_rand_generator.pool[i])); /* TODO right? What does this look like in assembly? */ } #ifdef PICO_RAND_SEED_PERSISTENT pico_rand_seed_load(); /* Set up timer for saving seed */ #endif /* PICO_RAND_SEED_PERSISTENT */ return 0; }
END_TEST START_TEST(tc_mld_mrsrrt) { struct mld_parameters *p; struct pico_device *dev = pico_null_create("dummy3"); struct pico_ipv6_link *link; struct pico_tree *filter = PICO_ZALLOC(sizeof(struct pico_tree)); int i,j, _i,_j,result; struct pico_ipv6_mcast_group g; struct mldv2_report *report; //Building example frame p = PICO_ZALLOC(sizeof(struct mld_parameters)); pico_string_to_ipv6("AAAA::1", p->mcast_link.addr); pico_string_to_ipv6("FF00::e007:707", p->mcast_group.addr); //no link fail_if(mld_mrsrrt(p) != -1); link = pico_ipv6_link_add(dev, p->mcast_link, p->mcast_link); link->mcast_compatibility = PICO_MLDV1; // wrong proto fail_if(mld_mrsrrt(p) != -1); link->mcast_compatibility = PICO_MLDV2; p->f = pico_proto_ipv6.alloc(&pico_proto_ipv6, sizeof(struct mldv2_report)+MLD_ROUTER_ALERT_LEN+sizeof(struct mldv2_group_record) +(0 *sizeof(struct pico_ip6))); fail_if(mld_mrsrrt(p) != -1); }
int pico_mock_network_write(struct mock_device*mock, const void *buf, int len) { struct mock_frame*frame; if (len > MOCK_MTU) return 0; frame = PICO_ZALLOC(sizeof(struct mock_frame)); if(!frame) { return 0; } if(mock->in_head == NULL) mock->in_head = frame; else mock->in_tail->next = frame; mock->in_tail = frame; mock->in_tail->buffer = PICO_ZALLOC((uint32_t)len); if(!mock->in_tail->buffer) return 0; memcpy(mock->in_tail->buffer, buf, (uint32_t)len); mock->in_tail->len = len; return len; }
END_TEST START_TEST(tc_pico_mld_process_in) { struct mld_parameters *p; struct pico_device *dev = pico_null_create("dummy3"); struct pico_ipv6_link *link; struct pico_tree *filter = PICO_ZALLOC(sizeof(struct pico_tree)); int i,j, _i,_j,result; struct pico_ipv6_mcast_group g; struct mldv2_report *report; //Building example frame p = PICO_ZALLOC(sizeof(struct mld_parameters)); pico_string_to_ipv6("AAAA::1", p->mcast_link.addr); pico_string_to_ipv6("FF00::e007:707", p->mcast_group.addr); //no link fail_if(pico_mld_generate_report(p) != -1); link = pico_ipv6_link_add(dev, p->mcast_link, p->mcast_link); pico_string_to_ipv6("AAAA::1", p->mcast_group.addr); fail_if(pico_mld_generate_report(p) != -1); pico_string_to_ipv6("FF00::e007:707", p->mcast_group.addr); link->mcast_compatibility = PICO_MLDV1; g.mcast_addr = p->mcast_group; g.MCASTSources.root = &LEAF; g.MCASTSources.compare = mcast_sources_cmp_ipv6; // No mcastsources tree link->mcast_compatibility = PICO_MLDV2; fail_if(pico_mld_generate_report(p) != -1); pico_tree_insert(link->MCASTGroups, &g); pico_tree_insert(&MLDParameters, p); link->mcast_compatibility = 99; fail_if(pico_mld_generate_report(p) != -1); link->mcast_compatibility = PICO_MLDV1; fail_if(pico_mld_generate_report(p) != 0); link->mcast_compatibility = PICO_MLDV2; for(_j =0; _j<3; _j++) { //FILTER (_j == 2) ? (result = -1) : (result = 0); for(_i=0; _i<3; _i++) { //FILTER if(_i == 2) result = -1; for(i = 0; i<3; i++) { //STATES for(j = 0; j<6; j++) { //EVENTS p->MCASTFilter = &_MCASTFilter; p->filter_mode = _i; g.filter_mode = _j; if(p->event == MLD_EVENT_DELETE_GROUP || p->event == MLD_EVENT_QUERY_RECV) p->event++; fail_if(pico_mld_generate_report(p) != result); p->state = i; p->event = j; if(result != -1 && p->f) {//in some combinations, no frame is created report = p->f->transport_hdr + MLD_ROUTER_ALERT_LEN; report->crc = short_be(pico_icmp6_checksum(p->f)); fail_if(pico_mld_process_in(p->f) != 0); } } } } } }
END_TEST START_TEST(tc_find_session_by_socket) { tftp_sessions = (struct pico_tftp_session *)PICO_ZALLOC(sizeof(struct pico_tftp_session)); tftp_sessions->socket = &example_socket; tftp_sessions->next = (struct pico_tftp_session *)PICO_ZALLOC(sizeof(struct pico_tftp_session)); tftp_sessions->socket = NULL; tftp_sessions->next = NULL; fail_if(find_session_by_socket(&example_socket) != tftp_sessions->next); }
static int pico_dns_client_user_callback(struct pico_dns_answer_suffix *asuffix, struct pico_dns_query *q) { uint32_t ip = 0; char *str = NULL; char *rdata = (char *) asuffix + sizeof(struct pico_dns_answer_suffix); switch (q->qtype) { case PICO_DNS_TYPE_A: ip = long_from(rdata); str = PICO_ZALLOC(PICO_DNS_IPV4_ADDR_LEN); pico_ipv4_to_string(str, ip); break; #ifdef PICO_SUPPORT_IPV6 case PICO_DNS_TYPE_AAAA: { struct pico_ip6 ip6; memcpy(&ip6.addr, rdata, sizeof(struct pico_ip6)); str = PICO_ZALLOC(PICO_DNS_IPV6_ADDR_LEN); pico_ipv6_to_string(str, ip6.addr); break; } #endif case PICO_DNS_TYPE_PTR: pico_dns_client_answer_domain(rdata); str = PICO_ZALLOC((size_t)(asuffix->rdlength - PICO_DNS_LABEL_INITIAL)); if (!str) { pico_err = PICO_ERR_ENOMEM; return -1; } memcpy(str, rdata + PICO_DNS_LABEL_INITIAL, short_be(asuffix->rdlength) - PICO_DNS_LABEL_INITIAL); break; default: dns_dbg("DNS ERROR: incorrect qtype (%u)\n", q->qtype); break; } if (q->retrans) { q->callback(str, q->arg); q->retrans = 0; PICO_FREE(str); pico_dns_client_del_query(q->id); } return 0; }
struct pico_device *pico_tun_create(char *name) { struct pico_device_tun *tun = PICO_ZALLOC(sizeof(struct pico_device_tun)); if (!tun) return NULL; if( 0 != pico_device_init((struct pico_device *)tun, name, NULL)) { dbg("Tun init failed.\n"); pico_tun_destroy((struct pico_device *)tun); return NULL; } tun->dev.overhead = 0; tun->fd = tun_open(name); if (tun->fd < 0) { dbg("Tun creation failed.\n"); pico_tun_destroy((struct pico_device *)tun); return NULL; } tun->dev.send = pico_tun_send; tun->dev.poll = pico_tun_poll; tun->dev.destroy = pico_tun_destroy; dbg("Device %s created.\n", tun->dev.name); return (struct pico_device *)tun; }
static int pico_dns_client_send(struct pico_dns_query *q) { uint16_t *paramID = PICO_ZALLOC(sizeof(uint16_t)); if (!paramID) { pico_err = PICO_ERR_ENOMEM; return -1; } dns_dbg("DNS: sending query to %08X\n", q->q_ns.ns.addr); if (!q->s) goto failure; if (pico_socket_connect(q->s, &q->q_ns.ns, short_be(PICO_DNS_NS_PORT)) < 0) goto failure; pico_socket_send(q->s, q->query, q->len); *paramID = q->id; pico_timer_add(PICO_DNS_CLIENT_RETRANS, pico_dns_client_retransmission, paramID); return 0; failure: PICO_FREE(paramID); return -1; }
static struct pico_device *pico_pcap_create(char *if_file_name, char *name, uint8_t *mac, int mode) { struct pico_device_pcap *pcap = PICO_ZALLOC(sizeof(struct pico_device_pcap)); char errbuf[2000]; if (!pcap) return NULL; if( 0 != pico_device_init((struct pico_device *)pcap, name, mac)) { dbg ("Pcap init failed.\n"); pico_pcap_destroy((struct pico_device *)pcap); return NULL; } pcap->dev.overhead = 0; if (mode == PICO_PCAP_MODE_LIVE) pcap->conn = pcap_open_live(if_file_name, 2000, 100, 10, errbuf); else pcap->conn = pcap_open_offline(if_file_name, errbuf); if (!pcap->conn) { pico_pcap_destroy((struct pico_device *)pcap); return NULL; } pcap->dev.send = pico_pcap_send; pcap->dev.poll = pico_pcap_poll; pcap->dev.destroy = pico_pcap_destroy; dbg("Device %s created.\n", pcap->dev.name); return (struct pico_device *)pcap; }
static struct pico_dns_ns *pico_dns_client_add_ns(struct pico_ip4 *ns_addr) { struct pico_dns_ns *dns = NULL, *found = NULL, test = {{0}}; dns = PICO_ZALLOC(sizeof(struct pico_dns_ns)); if (!dns) { pico_err = PICO_ERR_ENOMEM; return NULL; } dns->ns = *ns_addr; found = pico_tree_insert(&NSTable, dns); if (found) { /* nameserver already present */ PICO_FREE(dns); return found; } /* default NS found, remove it */ pico_string_to_ipv4(PICO_DNS_NS_DEFAULT, (uint32_t *)&test.ns.addr); found = pico_tree_findKey(&NSTable, &test); if (found && (found->ns.addr != ns_addr->addr)) pico_dns_client_del_ns(&found->ns); return dns; }
END_TEST START_TEST(tc_pico_mld_check_hopbyhop) { struct pico_ipv6_hbhoption *hbh = NULL; struct pico_ipv6_hbhoption _hbh; uint8_t *p; uint8_t options[8] = { PICO_PROTO_ICMP6, 0, PICO_IPV6_EXTHDR_OPT_ROUTER_ALERT,\ PICO_IPV6_EXTHDR_OPT_ROUTER_ALERT_DATALEN,0,0,1,0 }; int i = 0; int test = 0; fail_if(pico_mld_check_hopbyhop(hbh) != -1); _hbh.type = 1; _hbh.len = 0; fail_if(pico_mld_check_hopbyhop(&_hbh) != -1); _hbh.type = PICO_PROTO_ICMP6; _hbh.len = 1; fail_if(pico_mld_check_hopbyhop(&_hbh) != -1); hbh = (struct pico_ipv6_hbhoption *) PICO_ZALLOC(sizeof(struct pico_ipv6_hbhoption)+ 7); hbh->type = PICO_PROTO_ICMP6; hbh->len = 0; for(test = 0; test<7; test++) { p = (uint8_t *)hbh + sizeof(struct pico_ipv6_hbhoption); for(i = 0; i<6; i++ ) { if(i != test) *(p++) = options[i+2]; else *(p++) = 9; } if(test != 6) fail_if(pico_mld_check_hopbyhop(hbh) != -1); else fail_if(pico_mld_check_hopbyhop(hbh) != 0); } }
END_TEST START_TEST(tc_mld_stsdifs) { struct mld_parameters *p; struct pico_device *dev = pico_null_create("dummy3"); struct pico_ipv6_link *link; struct pico_ipv6_mcast_group g; struct mldv2_report *report; struct mld_timer t; //Building example frame p = PICO_ZALLOC(sizeof(struct mld_parameters)); pico_string_to_ipv6("AAAA::1", p->mcast_link.addr); pico_string_to_ipv6("FF00::e007:707", p->mcast_group.addr); //no link fail_if(mld_stsdifs(p) != -1); link = pico_ipv6_link_add(dev, p->mcast_link, p->mcast_link); link->mcast_compatibility = PICO_MLDV1; // no timer fail_if(mld_stsdifs(p) != -1); t.type = MLD_TIMER_GROUP_REPORT; t.mcast_link = p->mcast_link; t.mcast_group = p->mcast_group; pico_tree_insert(&MLDTimers, &t); fail_if(mld_stsdifs(p) != 0); //set flag pico_mld_flag = 1; fail_if(mld_stsdifs(p) != 0); }
END_TEST START_TEST(tc_mld_srst) { struct mld_parameters *p; struct pico_device *dev = pico_null_create("dummy3"); struct pico_ipv6_link *link; struct pico_ipv6_mcast_group g; struct mldv2_report *report; struct mld_timer t; //Building example frame p = PICO_ZALLOC(sizeof(struct mld_parameters)); pico_string_to_ipv6("AAAA::1", p->mcast_link.addr); pico_string_to_ipv6("FF00::e007:707", p->mcast_group.addr); p->MCASTFilter = &_MCASTFilter; p->filter_mode = 0; g.filter_mode = 0; g.mcast_addr = p->mcast_group; g.MCASTSources.root = &LEAF; g.MCASTSources.compare = mcast_sources_cmp_ipv6; pico_tree_insert(&MLDParameters, p); //no link fail_if(mld_srst(p) != -1); link = pico_ipv6_link_add(dev, p->mcast_link, p->mcast_link); link->mcast_compatibility = PICO_MLDV1; // invalid proto fail_if(mld_srst(p) != -1); link->mcast_compatibility = PICO_MLDV2; pico_tree_insert(link->MCASTGroups, &g); fail_if(mld_srst(p) != 0); }
static struct pico_dhcp_server_negotiation *pico_dhcp_server_add_negotiation(struct pico_device *dev, struct pico_dhcp_hdr *hdr) { struct pico_dhcp_server_negotiation *dhcpn = NULL; struct pico_dhcp_server_setting test = { 0 }; if (pico_dhcp_server_find_negotiation(hdr->xid)) return NULL; dhcpn = PICO_ZALLOC(sizeof(struct pico_dhcp_server_negotiation)); if (!dhcpn) { pico_err = PICO_ERR_ENOMEM; return NULL; } dhcpn->xid = hdr->xid; dhcpn->state = PICO_DHCP_STATE_DISCOVER; dhcpn->bcast = ((short_be(hdr->flags) & PICO_DHCP_FLAG_BROADCAST) != 0) ? (1) : (0); memcpy(dhcpn->hwaddr.addr, hdr->hwaddr, PICO_SIZE_ETH); test.dev = dev; dhcpn->dhcps = pico_tree_findKey(&DHCPSettings, &test); if (!dhcpn->dhcps) { dhcps_dbg("DHCP server WARNING: received DHCP message on unconfigured link %s\n", dev->name); PICO_FREE(dhcpn); return NULL; } dhcp_negotiation_set_ciaddr(dhcpn); pico_tree_insert(&DHCPNegotiations, dhcpn); return dhcpn; }
/* Re-seed the generator. Called when enough data has been used from the current 'run' */ static int pico_rand_reseed(uint8_t* seed, uint8_t seed_size) { uint8_t* sha_input = NULL; sha_input = (uint8_t*) PICO_ZALLOC (seed_size + PICO_RAND_ENCRYPT_KEY_SIZE); /* Seed size + 256b of current SHA hash key */ if (NULL == sha_input) { /* Failed to alloc, don't increment counter */ return 0; } else { memcpy (sha_input, pico_rand_generator.key, PICO_RAND_ENCRYPT_KEY_SIZE); /* Current key */ memcpy (sha_input + PICO_RAND_ENCRYPT_KEY_SIZE, seed, seed_size); /* New seed */ } wc_InitSha256(pico_rand_generator.sha); wc_Sha256Update(pico_rand_generator.sha, sha_input, seed_size + 32); wc_Sha256Final(pico_rand_generator.sha, pico_rand_generator.key); pico_rand_increment_counter(pico_rand_generator.counter); PICO_FREE (sha_input); return 1; }
struct pico_device * pico_netmap_create(char *interface, char *name, uint8_t *mac) { struct pico_device_netmap *netmap; char ifname[IFNAMSIZ + 7]; netmap = PICO_ZALLOC(sizeof(struct pico_device_netmap)); if (!netmap) { return NULL; } if (pico_device_init((struct pico_device *)netmap, name, mac)) { pico_netmap_destroy((struct pico_device *)netmap); return NULL; } sprintf(ifname, "netmap:%s", interface); netmap->dev.overhead = 0; netmap->conn = nm_open(ifname, NULL, 0, 0); if (! netmap->conn) { pico_netmap_destroy((struct pico_device *)netmap); return NULL; } netmap->dev.send = pico_netmap_send; netmap->dev.poll = pico_netmap_poll; netmap->dev.destroy = pico_netmap_destroy; return (struct pico_device *) netmap; }
struct pico_device *pico_ipc_create(const char *sock_path, const char *name, const uint8_t *mac) { struct pico_device_ipc *ipc = PICO_ZALLOC(sizeof(struct pico_device_ipc)); if (!ipc) return NULL; ipc->dev.mtu = IPC_MTU; if( 0 != pico_device_init((struct pico_device *)ipc, name, mac)) { dbg("Ipc init failed.\n"); pico_ipc_destroy((struct pico_device *)ipc); return NULL; } ipc->dev.overhead = 0; ipc->fd = ipc_connect(sock_path); if (ipc->fd < 0) { dbg("Ipc creation failed.\n"); pico_ipc_destroy((struct pico_device *)ipc); return NULL; } ipc->dev.send = pico_ipc_send; ipc->dev.poll = pico_ipc_poll; ipc->dev.destroy = pico_ipc_destroy; dbg("Device %s created.\n", ipc->dev.name); return (struct pico_device *)ipc; }
static struct pico_dns_query *pico_dns_client_add_query(struct pico_dns_header *hdr, uint16_t len, struct pico_dns_query_suffix *suffix, void (*callback)(char *, void *), void *arg) { struct pico_dns_query *q = NULL, *found = NULL; q = PICO_ZALLOC(sizeof(struct pico_dns_query)); if (!q) return NULL; q->query = (char *)hdr; q->len = len; q->id = short_be(hdr->id); q->qtype = short_be(suffix->qtype); q->qclass = short_be(suffix->qclass); q->retrans = 1; q->q_ns = *((struct pico_dns_ns *)pico_tree_first(&NSTable)); q->callback = callback; q->arg = arg; q->s = pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_UDP, &pico_dns_client_callback); if (!q->s) { PICO_FREE(q); return NULL; } found = pico_tree_insert(&DNSTable, q); if (found) { pico_err = PICO_ERR_EAGAIN; pico_socket_close(q->s); PICO_FREE(q); return NULL; } return q; }
/* Used in pico_sntp_sync_start */ struct pico_socket *pico_socket_open(uint16_t net, uint16_t proto, void (*wakeup)(uint16_t ev, struct pico_socket *s)) { struct pico_socket *sock = PICO_ZALLOC(sizeof(struct pico_socket)); (void) net; (void) proto; (void) wakeup; fail_unless (sock != NULL); return sock; }
END_TEST START_TEST(tc_sntp_receive_timeout) { struct sntp_server_ns_cookie *ck; struct pico_socket *sock; ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); fail_unless (ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); fail_unless (ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; sock = pico_socket_open(0, 0, &pico_sntp_client_wakeup); ck->sock = sock; sock->priv = ck; sntp_receive_timeout(0ull, ck); }
int main() { uint8_t mac[6]; uint32_t timer = 0; /* Obtain the ethernet MAC address */ eth_mac(mac); const char *ipaddr="192.168.0.150"; uint16_t port_be = 0; interrupt_register(irq_timer, GUEST_TIMER_INT); /* Configure the virtual ethernet driver */ struct pico_device* eth_dev = PICO_ZALLOC(sizeof(struct pico_device)); if(!eth_dev) { return 0; } eth_dev->send = eth_send; eth_dev->poll = eth_poll; eth_dev->link_state = eth_link_state; if( 0 != pico_device_init((struct pico_device *)eth_dev, "virt-eth", mac)) { printf ("\nDevice init failed."); PICO_FREE(eth_dev); return 0; } /* picoTCP initialization */ printf("\nInitializing pico stack\n"); pico_stack_init(); wolfSSL_Debugging_ON(); pico_string_to_ipv4(ipaddr, &my_eth_addr.addr); pico_string_to_ipv4("255.255.255.0", &netmask.addr); pico_ipv4_link_add(eth_dev, my_eth_addr, netmask); port_be = short_be(LISTENING_PORT); /* WolfSSL initialization only, to make sure libwolfssl.a is needed */ pico_https_setCertificate(cert_pem_2048, sizeof(cert_pem_2048)); pico_https_setPrivateKey(privkey_pem_2048, sizeof(privkey_pem_2048)); pico_https_server_start(0, serverWakeup); while (1){ eth_watchdog(&timer, 500); /* pooling picoTCP stack */ pico_stack_tick(); } return 0; }
END_TEST START_TEST(tc_pico_sntp_cleanup) { struct sntp_server_ns_cookie *ck; struct pico_socket *sock; ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); fail_unless (ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); fail_unless (ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; sock = pico_socket_open(0, 0, &pico_sntp_client_wakeup); ck->sock = sock; sock->priv = ck; pico_sntp_cleanup(ck, PICO_ERR_NOERR); }
END_TEST START_TEST(tc_dnsCallback) { /* TODO: test this: static void dnsCallback(char *ip, void *arg) */ char ip[] = "198.123.30.132"; struct sntp_server_ns_cookie *ck; ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); dnsCallback(ip, ck); }
struct mock_device *pico_mock_create(uint8_t*mac) { struct mock_device*mock = PICO_ZALLOC(sizeof(struct mock_device)); if(!mock) return NULL; mock->dev = PICO_ZALLOC(sizeof(struct pico_device)); if (!mock->dev) { PICO_FREE(mock); return NULL; } if(mac != NULL) { mock->mac = PICO_ZALLOC(6 * sizeof(uint8_t)); if(!mock->mac) { PICO_FREE(mock->mac); PICO_FREE(mock); return NULL; } memcpy(mock->mac, mac, 6); } if( 0 != pico_device_init((struct pico_device *)mock->dev, "mock", mac)) { dbg ("Loop init failed.\n"); pico_mock_destroy((struct pico_device *)mock->dev); if(mock->mac != NULL) PICO_FREE(mock->mac); PICO_FREE(mock); return NULL; } mock->dev->send = pico_mock_send; mock->dev->poll = pico_mock_poll; mock->dev->destroy = pico_mock_destroy; dbg("Device %s created.\n", mock->dev->name); pico_tree_insert(&mock_device_tree, mock); return mock; }
struct command_t *add_command(struct command_t *commands, char operation, char *filename, union pico_address *server_address) { struct command_t *command = PICO_ZALLOC(sizeof(struct command_t)); command->operation = operation; command->filename = filename; memcpy(&command->server_address, server_address, sizeof(union pico_address)); command->next = commands; return command; }
struct note_t *add_note(const char *filename, int fd, char direction) { struct note_t *note = PICO_ZALLOC(sizeof(struct note_t)); note->filename = strdup(filename); note->fd = fd; note->direction = direction; note->filesize = 0; note->next = clipboard; clipboard = note; return note; }
END_TEST START_TEST(tc_pico_sntp_client_wakeup) { /* TODO: test this: static void pico_sntp_client_wakeup(uint16_t ev, struct pico_socket *s) */ uint16_t event = PICO_SOCK_EV_ERR; struct sntp_server_ns_cookie *ck; struct pico_socket *sock; ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); fail_unless (ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); fail_unless (ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; sock = pico_socket_open(0, 0, &pico_sntp_client_wakeup); ck->sock = sock; sock->priv = ck; ck->cb_synced = cb_synced; printf("Started wakeup unit test\n"); pico_sntp_client_wakeup(event, sock); }