u16 __pseudoheader_checksum( ip_header const * ip ) { ip_pseudoheader ipph; ipph.src = ip->src_addr; ipph.dest = ip->dest_addr; ipph.proto = ip->proto; ipph.len = __htons(__ip_payload_length( ip )); ipph.sbz = 0; return __checksum_ex( 0, &ipph, sizeof(ipph) ); }
void __ip_make_header( ip_header * ip, u08 proto, u16 ident, u16 len, u32 dest ) { ip->version = 0x45; ip->tos = 0; ip->length = __htons( len ); ip->fraginfo = 0; ip->ident = ident; ip->dest_addr = dest; ip->src_addr = get_hostaddr(); ip->ttl = 128; ip->proto = proto; ip->checksum = ~__htons( __checksum( ip, sizeof(ip_header) ) ); }
uint32_t tcg_hash_extend(uint32_t addr, uint32_t len, uint32_t pcr) { struct TCG_HashAll tcg_hash_all; struct TCG_PassTroughtToTPM tcg_passtrough_to_tpm; char _unused[0x22]; tcg_hash_all.ipb_length = 0x0010; tcg_hash_all._reserved = 0x0000; tcg_hash_all.hash_data_ptr = addr; tcg_hash_all.hash_data_len = len; tcg_hash_all.algorithm_id = TPM_ALGO_SHA1; tcg_passtrough_to_tpm.ipb_length = 0x002a; tcg_passtrough_to_tpm._reserved1 = 0x0000; tcg_passtrough_to_tpm.opb_length = 0x0022; tcg_passtrough_to_tpm._reserved2 = 0x0000; tcg_passtrough_to_tpm.tpm_tag = __htons(TPM_TAG_RQU_COMMAND); tcg_passtrough_to_tpm.input_size = __htonl(0x00000022); tcg_passtrough_to_tpm.cmd_ordinal = __htonl(TPM_ORD_Extend); tcg_passtrough_to_tpm.pcr = __htonl(pcr); v86.addr = 0x1a; v86.eax = 0xbb05; v86.ebx = TCG_MAGIC; v86.ecx = 0x00000000; v86.edx = 0x00000000; v86.es = VTOPSEG(&tcg_hash_all); v86.edi = VTOPOFF(&tcg_hash_all); v86.ds = VTOPSEG(&tcg_passtrough_to_tpm.hash); v86.esi = VTOPOFF(&tcg_passtrough_to_tpm.hash); v86int(); if (v86.eax != TCG_PC_OK) return (v86.eax); v86.addr = 0x1a; v86.eax = 0xbb02; v86.ebx = TCG_MAGIC; v86.ecx = 0x00000000; v86.edx = 0x00000000; v86.es = VTOPSEG(&tcg_passtrough_to_tpm); v86.edi = VTOPOFF(&tcg_passtrough_to_tpm); v86.ds = VTOPSEG(&_unused); v86.esi = VTOPOFF(&_unused); v86int(); return (v86.eax); }
void udp_send( udp_sock sock, u32 to_ip, u16 to_port, u08 const * data, u16 len ) { udp_conn * conn = &udp_conns[sock]; u08 iface; if (!conn->handler) { log_printf( "udp: not_sock in send\n" ); return; } memset( &out, 0, sizeof( out ) ); if ( !arp_make_eth_header( &out.eth, to_ip, &iface ) ) return; out.eth.src = get_macaddr(); out.eth.ethertype = __htons( ethertype_ipv4 ); __ip_make_header( &out.ip, IPPROTO_UDP, 0, len + sizeof( ip_header ) + sizeof( udp_header ), to_ip ); out.udp.src_port = __htons(conn->port); out.udp.dest_port = __htons(to_port); out.udp.length = __htons( len + sizeof( udp_header ) ); if ( len ) memcpy( out.crap, data, len ); out.udp.checksum = ~__htons(__checksum_ex( __pseudoheader_checksum( &out.ip ), &out.udp, len + sizeof( udp_header ) )); __send_packet( iface, (u08 const *) &out, sizeof( eth_header ) + sizeof( ip_header ) + sizeof( udp_header ) + len ); }
uint16_t htons(uint16_t hs) { return (__htons(hs)); }