uint_32 _ki2c_polled_install ( /* [IN] A string that identifies the device for fopen */ char_ptr identifier, /* [IN] The I/O init data pointer */ KI2C_INIT_STRUCT_CPTR init_data_ptr ) { /* Body */ #if PE_LDD_VERSION if (PE_PeripheralUsed((uint_32)_bsp_get_i2c_base_address(init_data_ptr->CHANNEL))) { /* IO Device used by PE Component*/ return IO_DEVICE_EXISTS; } #endif return _io_i2c_polled_install(identifier, (uint_32 (_CODE_PTR_)(pointer, pointer _PTR_, char_ptr))_ki2c_polled_init, (uint_32 (_CODE_PTR_)(pointer, pointer))_ki2c_polled_deinit, (int_32 (_CODE_PTR_)(pointer, char_ptr, int_32))_ki2c_polled_rx, (int_32 (_CODE_PTR_)(pointer, char_ptr, int_32))_ki2c_polled_tx, (int_32 (_CODE_PTR_)(pointer, uint_32, uint_32_ptr))_ki2c_polled_ioctl, (pointer)init_data_ptr); } /* Endbody */
uint_32 _kuart_int_install ( /* [IN] A string that identifies the device for fopen */ char_ptr identifier, /* [IN] The I/O init data pointer */ KUART_INIT_STRUCT_CPTR init_data_ptr, /* [IN] The I/O queue size to use */ uint_32 queue_size ) { /* Body */ #if PE_LDD_VERSION if (PE_PeripheralUsed((uint_32)_bsp_get_serial_base_address(init_data_ptr->DEVICE))) { return IO_ERROR; } #endif return _io_serial_int_install(identifier, (uint_32 (_CODE_PTR_)(pointer, char _PTR_))_kuart_int_init, (uint_32 (_CODE_PTR_)(pointer))_kuart_int_enable, (uint_32 (_CODE_PTR_)(pointer,pointer))_kuart_int_deinit, (void (_CODE_PTR_)(pointer, char))_kuart_int_putc, (uint_32 (_CODE_PTR_)(pointer, uint_32, pointer))_kuart_polled_ioctl, (pointer)init_data_ptr, queue_size); } /* Endbody */
/*FUNCTION**************************************************************** * * Function Name : _dspi_polled_install * Returned Value : MQX error code * Comments : * Install an SPI device. * *END*********************************************************************/ uint_32 _dspi_polled_install ( /* [IN] A string that identifies the device for fopen */ char_ptr identifier, /* [IN] The I/O init data pointer */ DSPI_INIT_STRUCT_CPTR init_data_ptr ) { return _io_spi_polled_install(identifier, (uint_32 (_CODE_PTR_)(pointer, pointer _PTR_, char_ptr))_dspi_polled_init, (uint_32 (_CODE_PTR_)(pointer, pointer))_dspi_polled_deinit, (_mqx_int (_CODE_PTR_)(pointer, char_ptr, int_32))_dspi_polled_rx, (_mqx_int (_CODE_PTR_)(pointer, char_ptr, int_32))_dspi_polled_tx, (_mqx_int (_CODE_PTR_)(pointer, uint_32, _mqx_uint_ptr, uint_32))_dspi_polled_ioctl, (pointer)init_data_ptr); }
uint_32 _vf_rtc_if_install ( /* [IN] A string that identifies the device for fopen */ char_ptr identifier, /* [IN] The I/O init data pointer */ pointer init_data_ptr ) { /* Body */ return _io_rtc_if_install(identifier, (uint_32 (_CODE_PTR_)(pointer, char _PTR_))_vf_rtc_init, (uint_32 (_CODE_PTR_)(pointer, pointer))_vf_rtc_deinit, NULL, NULL, (uint_32 (_CODE_PTR_)(pointer, uint_32, uint_32_ptr))_vf_rtc_ioctl, init_data_ptr); } /* Endbody */
uint_32 _mcf54xx_uart_serial_int_install ( /* [IN] A string that identifies the device for fopen */ char_ptr identifier, /* [IN] The I/O init data pointer */ MCF54XX_UART_SERIAL_INIT_STRUCT_CPTR init_data_ptr, /* [IN] The I/O queue size to use */ uint_32 queue_size ) { /* Body */ return _io_serial_int_install(identifier, (uint_32 (_CODE_PTR_)(pointer, char _PTR_))_mcf54xx_uart_serial_int_init, (uint_32 (_CODE_PTR_)(pointer))_mcf54xx_uart_serial_int_enable, (uint_32 (_CODE_PTR_)(pointer,pointer))_mcf54xx_uart_serial_int_deinit, (void (_CODE_PTR_)(pointer, char))_mcf54xx_uart_serial_int_putc, (uint_32 (_CODE_PTR_)(pointer, uint_32, pointer))_mcf54xx_uart_serial_polled_ioctl, (pointer)init_data_ptr, queue_size); } /* Endbody */
bool has_chunk(chunk id) { return png_get_valid(m_png, m_info.get_png_info(), uint_32(id)) == uint_32(id); }
void ICMP_send_error_internal ( uint_8 type, /* [IN] the type to send */ uint_8 code, /* [IN] the code to send */ uint_32 param, /* [IN] a parameter */ IP_HEADER_PTR iph, /* [IN] the IP header */ RTCSPCB_PTR origpcb, /* [IN] pcb with bad packet */ uint_32 maxlen /* [IN] the max data len to send, 0 = default */ ) { /* Body */ ICMP_CFG_STRUCT_PTR ICMP_cfg_ptr = RTCS_getcfg(ICMP); RTCSPCB_PTR pcb; ICMP_ERR_HEADER_PTR icmph; _ip_address ipsrc = ntohl(iph->SOURCE); _ip_address ipdst = ntohl(iph->DEST); uint_16 iphdrlen = (ntohc(iph->VERSLEN) & 0x0F) << 2; uint_16 ippktlen = ntohs(iph->LENGTH) - iphdrlen; uint_16 checksum; _ip_address icmpsrc = IP_is_local(NULL,ipdst) ? ipdst : INADDR_ANY; uint_32 error; uchar_ptr buffer; uint_32 temp; #if RTCSCFG_ENABLE_NAT TCP_HEADER_PTR tcp_hdr; UDP_HEADER_PTR udp_hdr; IP_HEADER_PTR ip_hdr; uint_32 protocol; uint_16 src_port, dest_port; uint_32 (_CODE_PTR_ _PTR_ nat_exec)(RTCSPCB_PTR _PTR_); #endif /* ** Only include up to a maximum of maxlen bytes of data from the ** original IP datagram */ if (!maxlen) { maxlen = IP_DEFAULT_MTU - sizeof(IP_HEADER) - sizeof(ICMP_HEADER) - 4; } /* Endif */ if (origpcb) { temp = RTCSPCB_DATA(origpcb) - RTCSPCB_DATA_NETWORK(origpcb); if (maxlen > origpcb->HEADER_FRAG_USED + temp) { maxlen = origpcb->HEADER_FRAG_USED + temp; } /* Endif */ } /* Endif */ if (ippktlen + iphdrlen > maxlen) { ippktlen = maxlen - iphdrlen; } /* Endif */ /* Don't send an error in response to an ICMP error */ if (ntohc(iph->PROTOCOL) == IPPROTO_ICMP) { /* Make sure the packet has at least a 'TYPE' field */ if (ippktlen == 0) { return; } /* Endif */ icmph = (ICMP_ERR_HEADER_PTR)((uchar_ptr)iph + iphdrlen); if (!ICMPTYPE_ISQUERY(ntohc(icmph->HEAD.TYPE))) { return; } /* Endif */ } /* Endif */ IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_TOTAL++); /* Allocate a PCB */ pcb = RTCSPCB_alloc_send(); if (pcb == NULL) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return; } /* Endif */ //RTCSLOG_PCB_ALLOC(pcb); if (origpcb) { /* Add a dependency and a pointer to the ICMP data */ RTCSPCB_depend(pcb, origpcb); error = RTCSPCB_append_fragment(pcb, iphdrlen + ippktlen, (uchar_ptr)iph); } else { /* Reserve space for the ICMP data */ buffer = RTCS_mem_alloc_system(iphdrlen + ippktlen); if (!buffer) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); IF_ICMP_STATS_ENABLED(RTCS_seterror(&ICMP_cfg_ptr->STATS.ERR_TX, RTCSERR_OUT_OF_MEMORY, (uint_32)pcb)); RTCSLOG_PCB_FREE(pcb, RTCSERR_OUT_OF_MEMORY); RTCSPCB_free(pcb); return; } /* Endif */ _mem_set_type(buffer, MEM_TYPE_ICMP_DATA); _mem_copy(iph, buffer, iphdrlen + ippktlen); error = RTCSPCB_append_fragment_autofree(pcb, iphdrlen + ippktlen, buffer); if (error) { _mem_free(buffer); } /* Endif */ } /* Endif */ if (!error) { error = RTCSPCB_insert_header(pcb, sizeof(ICMP_HEADER) + 4); } /* Endif */ if (error) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); IF_ICMP_STATS_ENABLED(RTCS_seterror(&ICMP_cfg_ptr->STATS.ERR_TX, error, (uint_32)pcb)); RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); return; } /* Endif */ RTCSLOG_PCB_WRITE(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_ICMP), 0); /* Build the header */ icmph = (ICMP_ERR_HEADER_PTR)RTCSPCB_DATA(pcb); htonc(icmph->HEAD.TYPE, type); htonc(icmph->HEAD.CODE, code); htons(icmph->HEAD.CHECKSUM, 0); htonl(icmph->DATA, param); checksum = IP_Sum_PCB (0, pcb); checksum = IP_Sum_invert(checksum); htons(icmph->HEAD.CHECKSUM, checksum); #if RTCSCFG_ENABLE_ICMP_STATS /* Update the statistics */ switch (type) { case ICMPTYPE_DESTUNREACH: ICMP_cfg_ptr->STATS.ST_TX_DESTUNREACH++; break; case ICMPTYPE_TIMEEXCEED: ICMP_cfg_ptr->STATS.ST_TX_TIMEEXCEED++; break; case ICMPTYPE_PARMPROB: ICMP_cfg_ptr->STATS.ST_TX_PARMPROB++; break; case ICMPTYPE_SRCQUENCH: ICMP_cfg_ptr->STATS.ST_TX_SRCQUENCH++; break; case ICMPTYPE_REDIRECT: ICMP_cfg_ptr->STATS.ST_TX_REDIRECT++; break; case ICMPTYPE_ECHO_REQ: ICMP_cfg_ptr->STATS.ST_TX_ECHO_REQ++; break; case ICMPTYPE_ECHO_REPLY: ICMP_cfg_ptr->STATS.ST_TX_ECHO_REPLY++; break; case ICMPTYPE_TIME_REQ: ICMP_cfg_ptr->STATS.ST_TX_TIME_REQ++; break; case ICMPTYPE_TIME_REPLY: ICMP_cfg_ptr->STATS.ST_TX_TIME_REPLY++; break; case ICMPTYPE_INFO_REQ: ICMP_cfg_ptr->STATS.ST_TX_INFO_REQ++; break; case ICMPTYPE_INFO_REPLY: ICMP_cfg_ptr->STATS.ST_TX_INFO_REPLY++; break; default: ICMP_cfg_ptr->STATS.ST_TX_OTHER++; break; } /* Endswitch */ #endif #if RTCSCFG_ENABLE_NAT /* Reverse NAT (if it is installed) on the origpcb, otherwise the icmp error will not get sent to the original src */ nat_exec = RTCS_getcfg(NAT); if (origpcb && nat_exec && *nat_exec) { // swap src and dst IPs and ports so NAT_apply // will process the pcb ip_hdr = (IP_HEADER_PTR)RTCSPCB_DATA(origpcb); protocol = ntohc(ip_hdr->PROTOCOL); // Swap ports if it is udp or tcp if ((protocol == IPPROTO_TCP) || (protocol == IPPROTO_UDP)) { switch(protocol) { case IPPROTO_TCP: tcp_hdr = (TCP_HEADER_PTR)((uchar_ptr)ip_hdr + IPH_LEN(ip_hdr)); dest_port = ntohs(tcp_hdr->dest_port); src_port = ntohs(tcp_hdr->source_port); htons(tcp_hdr->dest_port, src_port); htons(tcp_hdr->source_port, dest_port); break; case IPPROTO_UDP: udp_hdr = (UDP_HEADER_PTR)((uchar_ptr)ip_hdr + IPH_LEN(ip_hdr)); dest_port = ntohs(udp_hdr->DEST_PORT); src_port = ntohs(udp_hdr->SRC_PORT); htons(udp_hdr->DEST_PORT, src_port); htons(udp_hdr->SRC_PORT, dest_port); break; default: // should not get here break; } } // swap IPs ipsrc = ntohl(ip_hdr->SOURCE); ipdst = ntohl(ip_hdr->DEST); htonl(ip_hdr->SOURCE, ipdst); htonl(ip_hdr->DEST,ipsrc); // call NAT error = (*nat_exec)(&origpcb); if (!error) { // swap IPs and ports back ip_hdr = (IP_HEADER_PTR)RTCSPCB_DATA(origpcb); protocol = ntohc(ip_hdr->PROTOCOL); // swap ports if it is udp or tcp if ((protocol == IPPROTO_TCP) || (protocol == IPPROTO_UDP)) { switch(protocol) { case IPPROTO_TCP: tcp_hdr = (TCP_HEADER_PTR)((uchar_ptr)ip_hdr + IPH_LEN(ip_hdr)); dest_port = ntohs(tcp_hdr->dest_port); src_port = ntohs(tcp_hdr->source_port); htons(tcp_hdr->dest_port, src_port); htons(tcp_hdr->source_port, dest_port); break; case IPPROTO_UDP: udp_hdr = (UDP_HEADER_PTR)((uchar_ptr)ip_hdr + IPH_LEN(ip_hdr)); dest_port = ntohs(udp_hdr->DEST_PORT); src_port = ntohs(udp_hdr->SRC_PORT); htons(udp_hdr->DEST_PORT, src_port); htons(udp_hdr->SRC_PORT, dest_port); break; default: // should not get here break; } } // swap IPs ipsrc = ntohl(ip_hdr->SOURCE); ipdst = ntohl(ip_hdr->DEST); htonl(ip_hdr->SOURCE, ipdst); htonl(ip_hdr->DEST,ipsrc); // Recalculate the cksum htons(icmph->HEAD.CHECKSUM, 0); checksum = IP_Sum_PCB (0, pcb); checksum = IP_Sum_invert(checksum); htons(icmph->HEAD.CHECKSUM, checksum); // recalculate icmpsrc, and use new ipsrc. ipdst = ntohl(ip_hdr->DEST); ipsrc = ntohl(ip_hdr->SOURCE); icmpsrc = IP_is_local(NULL,ipdst) ? ipdst : INADDR_ANY; } } #endif /* Send it */ IP_send(pcb, IPPROTO_ICMP, icmpsrc, ipsrc, 0); } /* Endbody */