bool IGMP_send_report ( ip_mreq *igrp, uint16_t type ) { /* Body */ IGMP_CFG_STRUCT_PTR IGMP_cfg_ptr = RTCS_getcfg(IGMP); uint32_t error; uint16_t checksum; RTCSPCB_PTR pcb; IGMP_HEADER_PTR header; IP_IF_PTR ipif; _ip_address ipdst; IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_TOTAL++); /* never send a report for the local groups */ if (IN_LOCAL_MULTICAST(igrp->imr_multiaddr.s_addr)) { return TRUE; } /* Endif */ /* get the interface with its ip address */ ipif = IP_find_if(igrp->imr_interface.s_addr); if (ipif == NULL) { IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return FALSE; } /* Endif */ pcb = RTCSPCB_alloc_send(); if (pcb == NULL) { IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return FALSE; } /* Endif */ //RTCSLOG_PCB_ALLOC(pcb); error = RTCSPCB_insert_header(pcb, sizeof(IGMP_HEADER)); if (error) { RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return FALSE; } /* Endif */ RTCSLOG_PCB_WRITE(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_IGMP), 1); #ifdef IGMP_V2 /* check if routers igmpv1 are present or not */ if (type == IGMPTYPE_V2_REPORT && ipif->IGMP_V1_ROUTER_FLAG) { uint32_t curTime = RTCS_time_get(); /* WORK: handle the overflow (see tcp seq) */ if (curTime < ipif->IGMP_V1_ROUTER_TIMEOUT) { type = IGMPTYPE_V1_REPORT; } else { /* if the timeout expired, clear the flag */ ipif->IGMP_V1_ROUTER_FLAG = 0; } /* Endif */ } /* Endif */ #endif /* IGMP_V2 */ /* build the igmp packet */ header = (IGMP_HEADER_PTR)RTCSPCB_DATA(pcb); mqx_htonc(header->TYPE, type); mqx_htonc(header->MAX_RESP_TIME, 0); mqx_htons(header->CHECKSUM, 0); mqx_htonl(header->GROUP_ADDRESS, igrp->imr_multiaddr.s_addr); checksum = _mem_sum_ip(0, sizeof(IGMP_HEADER), header); checksum = IP_Sum_invert(checksum); mqx_htons(header->CHECKSUM, checksum); /* WORK: for IGMP_V2, add a router alert option but currently ip layer doesnt support ip options */ /* send the igmp packet */ ipdst = igrp->imr_multiaddr.s_addr; #ifdef IGMP_V2 if (type == IGMPTYPE_LEAVE) { ipdst = INADDR_ALLROUTERS_GROUP; } /* Endif */ #endif IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.ST_TX_REPORT++); /* WORK: not always true for IGMP_V2 */ error = IP_send(pcb, IPPROTO_IGMP | IPTTL(1), igrp->imr_interface.s_addr, ipdst, RTCS_MSG_NOLOOP); return TRUE; } /* Endbody */
/*FUNCTION*------------------------------------------------------------- * * Function Name : ICMP6_send_echo * Parameters : * * _ip_address ipaddress [IN] destination IP address * uint_32 timeout [IN/OUT] timeout/rtt * uint_16 id [IN] identification for echo message. * uint_16 seq not used * * Comments : * Send an ICMP Echo Request packet. * *END*-----------------------------------------------------------------*/ void ICMP6_send_echo(ICMP_ECHO_PARAM_PTR parms) { #if RTCSCFG_ENABLE_IP6 ICMP6_CFG_STRUCT_PTR ICMP6_cfg_ptr = RTCS_getcfg(ICMP6); RTCSPCB_PTR pcb; ICMP6_ECHO_HEADER_PTR packet; _rtcs_if_handle ihandle_dest = NULL; uint_32 error; IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_TOTAL++); parms->seq = ICMP6_cfg_ptr->ECHO_SEQ++; pcb = RTCSPCB_alloc_send(); if (pcb == NULL) { IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); RTCSCMD_complete(parms, RTCSERR_PCB_ALLOC); return; } if(parms->ping_param->data_buffer && parms->ping_param->data_buffer_size) { error = RTCSPCB_append_fragment(pcb, parms->ping_param->data_buffer_size, parms->ping_param->data_buffer); if (error) { IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_ERRORS++); RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); RTCSCMD_complete(parms, error); return; } } error = RTCSPCB_insert_header(pcb, sizeof(ICMP6_ECHO_HEADER)); if (error) { IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_ERRORS++); IF_ICMP6_STATS_ENABLED(RTCS_seterror(&ICMP6_cfg_ptr->STATS.ERR_TX, error, (uint_32)pcb)); RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); RTCSCMD_complete(parms, error); return; } RTCSLOG_PCB_WRITE(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_ICMPV6), 0); packet = (ICMP6_ECHO_HEADER_PTR)RTCSPCB_DATA(pcb); pcb->TRANSPORT_LAYER = (uchar_ptr)packet; htonc(packet->HEAD.TYPE, ICMP6_TYPE_ECHO_REQ); htonc(packet->HEAD.CODE, 0); htons(packet->HEAD.CHECKSUM, 0); htons(packet->ID, parms->ping_param->id); htons(packet->SEQ, parms->seq); pcb->IP_SUM = IP_Sum_PCB(RTCSPCB_SIZE(pcb), pcb); pcb->IP_SUM_PTR = packet->HEAD.CHECKSUM; if(((sockaddr_in6 *)(&parms->ping_param->addr))->sin6_scope_id) { ihandle_dest = ip6_if_get_by_scope_id(((sockaddr_in6 *)(&parms->ping_param->addr))->sin6_scope_id); } parms->EXPIRE.TIME = parms->ping_param->timeout; parms->EXPIRE.EVENT = ICMP6_expire_echo; parms->EXPIRE.PRIVATE = parms; parms->start_time = RTCS_time_get(); /* get timestamp */ error = IP6_send(pcb, IPPROTO_ICMPV6|IPTTL(parms->ping_param->hop_limit), NULL/*ipsrc*/, &((sockaddr_in6 *)(&parms->ping_param->addr))->sin6_addr/*ipdest*/, ihandle_dest, 0); if (error != RTCS_OK) { IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); RTCSCMD_complete(parms, error); return; } /* ** If there is no error add the parm struct to config struct ** and initiate the event timer */ IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.ST_TX_ECHO_REQ++); /* add the prameter structure to ICMP cfg */ parms->NEXT = ICMP6_cfg_ptr->ECHO_PARAM_HEAD; if (parms->NEXT) { parms->NEXT->PREV = &parms->NEXT; } /* Endif */ ICMP6_cfg_ptr->ECHO_PARAM_HEAD = parms; parms->PREV = &ICMP6_cfg_ptr->ECHO_PARAM_HEAD; TCPIP_Event_add(&parms->EXPIRE); #else RTCSCMD_complete(parms, RTCSERR_IP_IS_DISABLED); #endif /* RTCSCFG_ENABLE_IP6 */ }