33 #ifndef SYSTEM_CORE_INC_NET_OC_NET_H_ 34 #define SYSTEM_CORE_INC_NET_OC_NET_H_ 38 #include <oc_baudrate.h> 41 #include <oc_stdlib.h> 52 #define _________________________________________DEFINITIONS_SECTION________________________________________________________________________ 57 #define IEEE_802_3_MAC_ADDRESS_LENGTH 6 58 #define IEEE_802_3_ETHERNET_MTU 1500 59 #define IEEE_802_3_MINIMUM_PAYLOAD 42 64 #define MAC_ADDRESS_LENGTH IEEE_802_3_MAC_ADDRESS_LENGTH 65 #define NETWORK_MTU IEEE_802_3_ETHERNET_MTU 66 #define MINIMUM_PAYLOAD IEEE_802_3_MINIMUM_PAYLOAD 67 #define IPv4_MAXIMUM_DATA_LENGTH (NETWORK_MTU - sizeof(oC_Net_Ipv4PacketHeader_t)) 68 #define IPv6_MAXIMUM_DATA_LENGTH (NETWORK_MTU - sizeof(oC_Net_Ipv6PacketHeader_t)) 74 #define MAXIMUM_NETWORK_INTERFACES 0xFFFFFFFF 75 #define MAXIMUM_FRIENDLY_INTERFACE_NAME 100 76 #define DHCP_SERVER_NAME_LENGTH 64 77 #define MAXIMUM_PACKET_SIZE UINT16_MAX 79 #undef _________________________________________DEFINITIONS_SECTION________________________________________________________________________ 86 #define _________________________________________FUNCTION_LIKE_MACROS_SECTION_______________________________________________________________ 88 #define IP(A,B,C,D) ( ( (D) << 0 ) | ( (C) << 8 ) | ( (B) << 16 ) | ( (A) << 24 )) 90 #undef _________________________________________FUNCTION_LIKE_MACROS_SECTION_______________________________________________________________ 98 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 233 #elif defined(BIG_ENDIAN) 234 # error The structure is not defined for BIG_ENDIAN 236 # error Endianess is not defined 259 #elif defined(BIG_ENDIAN) 260 # error The structure is not defined for BIG_ENDIAN 262 # error Endianess is not defined 277 uint8_t
Data[IPv4_MAXIMUM_DATA_LENGTH];
291 uint8_t
Data[IPv6_MAXIMUM_DATA_LENGTH];
475 char DhcpServerName[DHCP_SERVER_NAME_LENGTH];
530 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 537 #define _________________________________________INLINE_SECTION_____________________________________________________________________________ 547 #if defined(LITTLE_ENDIAN) 548 return (v >> 8) | (v << 8);
549 #elif defined(BIG_ENDIAN) 552 # error Unknown endianess 564 #if defined(LITTLE_ENDIAN) 566 #elif defined(BIG_ENDIAN) 569 # error Unknown endianess 603 uint16_t * array = Buffer;
604 uint16_t arraySize = Size /
sizeof(uint16_t);
607 oC_SaveIfFalse(
"oC_Net_ConvertBufferToNetworkEndianess: " , isram(Buffer) , oC_ErrorCode_AddressNotInRam )
608 && oC_SaveIfFalse(
"oC_Net_ConvertBufferToNetworkEndianess: (size is 0)" , Size > 0 , oC_ErrorCode_SizeNotCorrect )
609 && oC_SaveIfFalse(
"oC_Net_ConvertBufferToNetworkEndianess: (size not aligned to 2 bytes)" , Size %
sizeof(uint16_t) == 0 , oC_ErrorCode_SizeNotAligned )
612 for(uint16_t i = 0 ; i < arraySize ; i++)
627 uint16_t * array = Buffer;
628 uint16_t arraySize = Size /
sizeof(uint16_t);
631 oC_SaveIfFalse(
"oC_Net_ConvertBufferFromNetworkEndianess: " , isram(Buffer) , oC_ErrorCode_AddressNotInRam )
632 && oC_SaveIfFalse(
"oC_Net_ConvertBufferFromNetworkEndianess: (size is 0)" , Size > 0 , oC_ErrorCode_SizeNotCorrect )
633 && oC_SaveIfFalse(
"oC_Net_ConvertBufferFromNetworkEndianess: (size not aligned to 2 bytes)" , Size %
sizeof(uint16_t) == 0 , oC_ErrorCode_SizeNotAligned )
636 for(uint16_t i = 0 ; i < arraySize ; i++)
661 return sprintf_s( *outName ,
sizeof(*outName) ,
"%s#%X" , Prefix , Index);
679 return sscanf(MacAddressString,
"%x:%x:%x:%x:%x:%x" , &outMacAddress[0], &outMacAddress[1], &outMacAddress[2],
680 &outMacAddress[3], &outMacAddress[4], &outMacAddress[5]);
691 const char * name =
"unknown";
727 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
730 ErrorCondition( isaddresscorrect(HardwareAddress) , oC_ErrorCode_WrongAddress )
731 && ErrorCondition( HardwareAddress->
Filled , oC_ErrorCode_HardwareAddressIsEmpty )
732 && ErrorCondition( isram(outString) , oC_ErrorCode_OutputAddressNotInRAM )
733 && ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect )
739 sprintf_s(outString,Size,
"%02X:%02X:%02X:%02X:%02X:%02X",
747 errorCode = oC_ErrorCode_None;
750 errorCode = oC_ErrorCode_UnknownHardwareType;
774 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
777 ErrorCondition( isram(outString) , oC_ErrorCode_OutputAddressNotInRAM )
778 && ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect )
781 sprintf_s(outString, Size,
"%d.%d.%d.%d",
782 (Address & 0xFF000000) >> 24,
783 (Address & 0x00FF0000) >> 16,
784 (Address & 0x0000FF00) >> 8,
785 (Address & 0x000000FF) >> 0
787 errorCode = oC_ErrorCode_None;
809 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
812 ErrorCondition( isaddresscorrect(Address) , oC_ErrorCode_WrongAddress )
813 && ErrorCondition( isram(outString) , oC_ErrorCode_OutputAddressNotInRAM )
814 && ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect )
823 errorCode = oC_ErrorCode_NotImplemented;
827 errorCode = oC_ErrorCode_UnknownAddressType;
849 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
852 ErrorCondition( isaddresscorrect(Address) , oC_ErrorCode_WrongAddress )
853 && ErrorCondition( isram(outAddress) , oC_ErrorCode_OutputAddressNotInRAM )
856 uint8_t bytesArray[16] = {0};
860 ErrorCode( sscanf(Address,
"%d.%d.%d.%d", &bytesArray[0], &bytesArray[1], &bytesArray[2], &bytesArray[3] ) )
861 || ErrorCode( sscanf(Address,
"%d.%d.%d.%d:%d", &bytesArray[0], &bytesArray[1], &bytesArray[2], &bytesArray[3], &port ) )
865 outAddress->
Port = port;
866 outAddress->
IPv4 = (bytesArray[0] << 24)
867 | (bytesArray[1] << 16)
868 | (bytesArray[2] << 8)
869 | (bytesArray[3] << 0);
870 errorCode = oC_ErrorCode_None;
873 ErrorCode( sscanf(Address,
"%x:%x:%x:%x:%x:%x:%x:%x", &bytesArray[0], &bytesArray[1], &bytesArray[2], &bytesArray[3],
874 &bytesArray[4], &bytesArray[5], &bytesArray[6], &bytesArray[7]) )
878 outAddress->
Port = port;
879 outAddress->
IPv6.
LowPart = (((uint64_t)bytesArray[0] ) << 0 )
880 | (((uint64_t)bytesArray[1] ) << 8 )
881 | (((uint64_t)bytesArray[2] ) << 16)
882 | (((uint64_t)bytesArray[3] ) << 24)
883 | (((uint64_t)bytesArray[4] ) << 32)
884 | (((uint64_t)bytesArray[5] ) << 40)
885 | (((uint64_t)bytesArray[6] ) << 48)
886 | (((uint64_t)bytesArray[7] ) << 56);
887 outAddress->
IPv6.
HighPart = (((uint64_t)bytesArray[8] ) << 0 )
888 | (((uint64_t)bytesArray[9] ) << 8 )
889 | (((uint64_t)bytesArray[10]) << 16)
890 | (((uint64_t)bytesArray[11]) << 24)
891 | (((uint64_t)bytesArray[12]) << 32)
892 | (((uint64_t)bytesArray[13]) << 40)
893 | (((uint64_t)bytesArray[14]) << 48)
894 | (((uint64_t)bytesArray[15]) << 56);
895 errorCode = oC_ErrorCode_None;
899 errorCode = oC_ErrorCode_IpAddressNotCorrect;
920 bool correct =
false;
922 if(isaddresscorrect(Address))
953 if(isaddresscorrect(Address))
957 empty = Address->
IPv4 == 0;
984 return (IP & Mask) == (Subnet & Mask);
1003 bool belong =
false;
1005 if(isaddresscorrect(Address) && isaddresscorrect(Subnet) && isaddresscorrect(Mask) && Address->
Type == Subnet->
Type)
1013 oC_SaveError(
"Net::IsAddressInSubnet - IPv6 version - ", oC_ErrorCode_NotImplemented);
1037 if(isaddresscorrect(Address1) && isaddresscorrect(Address2) && Address1->
Type == Address2->
Type)
1041 same = Address1->
IPv4 == Address2->
IPv4;
1080 if(isaddresscorrect(Packet))
1086 if( WithHeader ==
false )
1112 bool success =
false;
1114 if(isaddresscorrect(Packet))
1129 uint16_t * word = (
void*)Packet;
1135 kdebuglog(oC_LogType_Error,
"oC_Net_ConvertHeaderToNetworkEndianess: not implemented for IPv6 yet\n");
1139 kdebuglog(oC_LogType_Error,
"oC_Net_ConvertHeaderToNetworkEndianess: incorrect packet type %d\n", Packet->
IPv6.
Header.
Version);
1154 bool success =
false;
1156 if(isaddresscorrect(Packet))
1173 uint16_t * word = (
void*)Packet;
1180 kdebuglog(oC_LogType_Error,
"not implemented for IPv6 yet\n");
1184 kdebuglog(oC_LogType_Error,
"oC_Net_ConvertHeaderFromNetworkEndianess: incorrect packet type %d\n", Packet->
IPv4.
Header.
IHL);
1201 oC_MemorySize_t size = 0;
1206 default: size = 0;
break;
1220 oC_MemorySize_t size = 0;
1222 if(isaddresscorrect(Address))
1224 switch(Address->
Type)
1242 const char * name =
"unknown";
1247 default: name =
"unhandled in oC_Net_GetHardwareTypeName";
1261 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1263 if(ErrorCondition(isram(outName), oC_ErrorCode_OutputAddressNotInRAM))
1268 const char * mainLayerName =
"unknownMainLayer";
1282 errorCode = sprintf_s(outName,Size,
"%s:%d", mainLayerName, subLayer);
1296 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1299 ErrorCondition( isram(outLayer) , oC_ErrorCode_OutputAddressNotInRAM )
1300 && ErrorCondition( isaddresscorrect(Name) , oC_ErrorCode_WrongAddress )
1303 uint32_t subLayer = 0;
1308 } layerStrings[] = {
1323 errorCode = oC_ErrorCode_UnknownLayer;
1325 oC_ARRAY_FOREACH_IN_ARRAY(layerStrings,layer)
1327 if(string_contains(Name,layer->Name,
false))
1329 *outLayer = layer->Layer;
1330 errorCode = oC_ErrorCode_None;
1335 string_contains(Name,
":",
true)
1336 && ErrorCode(sscanf(Name,
"%*s:%u", &subLayer))
1339 *outLayer |= subLayer;
1374 if(isaddresscorrect(Packet))
1390 bool success =
false;
1402 kdebuglog(oC_LogType_Error,
"oC_Net_SetPacketSize:: IPv6 is not ready yet\n", Packet->
IPv4.
Header.
Version);
1406 kdebuglog(oC_LogType_Error,
"oC_Net_SetPacketSize:: incorrect packet version: %d\n", Packet->
IPv4.
Header.
Version);
1423 if(isaddresscorrect(Packet))
1494 memcpy( Packet->
IPv4.
Data, Data, Size );
1499 memcpy( Packet->
IPv6.
Data, Data, Size );
1516 oC_SaveIfFalse(
"Net::New-Packet - Allocator is not correct - " , isaddresscorrect(Allocator) , oC_ErrorCode_WrongAddress )
1519 && oC_SaveIfFalse(
"Net::New-Packet - Size is not correct - " , Size > 0 , oC_ErrorCode_SizeNotCorrect )
1521 && oC_SaveIfFalse(
"Net::New-Packet - Data address is not correct - " , Data ==
NULL || isaddresscorrect(Data) , oC_ErrorCode_SizeNotCorrect )
1526 uint16_t packetSize = oC_MAX(headerSize + Size,
sizeof(
oC_Net_Packet_t));
1528 if(oC_SaveIfFalse(
"Net::New-Packet - Fatal error - ", packetSize > Size , oC_ErrorCode_SizeTooBig))
1530 packet = kmalloc( packetSize , Allocator, AllocationFlags_ZeroFill );
1532 if(oC_SaveIfFalse(
"Net::New-Packet - cannot allocate memory for a packet - ", packet !=
NULL , oC_ErrorCode_AllocationError ))
1563 bool success =
false;
1565 if(isram(Packet) && isram(*Packet))
1567 success = kfree(*Packet,AllocationFlags_Default);
1581 static inline uint16_t
oC_Net_CalculateChecksum(
const void * Buffer , uint16_t Size , uint16_t InitialValue ,
bool ConvertEndianess ,
bool PrepareChecksumToSend )
1583 uint32_t checksum = InitialValue;
1585 if(isaddresscorrect(Buffer) && Size > 0)
1587 const uint16_t * array = Buffer;
1588 uint16_t count = Size /
sizeof(uint16_t);
1590 for(uint16_t i = 0 ; i < count ; i++)
1594 checksum += valueInNetworkEndianess;
1596 while(checksum >> 16)
1598 checksum = (checksum & 0xFFFF) + (checksum >> 16);
1602 if(Size %
sizeof(uint16_t))
1604 if(ConvertEndianess)
1606 checksum += (((uint8_t*)Buffer)[Size-1]) << 8;
1610 checksum += ((uint8_t*)Buffer)[Size-1];
1614 while(checksum >> 16)
1616 checksum = (checksum & 0xFFFF) + (checksum >> 16);
1619 if(PrepareChecksumToSend)
1621 checksum = (~checksum) & 0xFFFF;
1630 return (uint16_t)checksum;
1641 uint16_t checksum = 0;
1643 if(isaddresscorrect(Packet))
1650 uint16_t headerSize = Packet->
IPv4.
Header.
IHL *
sizeof(uint32_t);
1665 #undef _________________________________________INLINE_SECTION_____________________________________________________________________________ oC_Net_Ipv4_t SourceIp
Source IP address.
static bool oC_Net_Packet_SetSize(oC_Net_Packet_t *Packet, uint16_t Size)
sets size of the packet
static oC_MemorySize_t oC_Net_GetAddressSize(const oC_Net_Address_t *Address)
returns size of IP address
Internet Group Management Protocol.
The data link layer or layer 2 is the second layer of the seven-layer OSI model of computer networkin...
static void oC_Net_ConvertBufferFromNetworkEndianess(void *Buffer, uint16_t Size)
converts buffer from network endianess
static bool oC_Net_AreAddressesTheSame(const oC_Net_Address_t *Address1, const oC_Net_Address_t *Address2)
returns true if both pointers stores the same address
oC_Net_Ipv4_t NetIP
IP of the local network (router IP)
uint32_t Length
Length of the packet in bytes.
oC_Net_InterfaceIndex_t InterfaceIndex
Index of the interface in the driver.
struct PACKED oC_Net_Ipv6Packet_t
stores IPv6 packet
uint64_t HighPart
High 8 bytes of the IPv6 address.
The file with interface for the GPIO driver.
static int oC_Net_MacAddressFromString(const char *MacAddressString, oC_Net_MacAddress_t outMacAddress)
reads MAC address from the string
uint32_t QoS
Quality of Service or Type of Service - describes the priority of the packet
oC_Net_Protocol_t Protocol
IP Protocol.
oC_MemorySize_t TransmittedBytes
Number of transmitted bytes.
uint32_t HopLimit
The same as TTL from the IPv4 header - time of packet's live.
In the seven-layer OSI model of computer networking, the presentation layer is layer 6 and serves as ...
static oC_Net_Packet_t * oC_Net_Packet_New(Allocator_t Allocator, oC_Net_PacketType_t Type, void *Data, uint16_t Size)
allocates memory for a packet
In the seven-layer OSI model of computer networking, the network layer is layer 3.
Mask to get the sublayer of the OSI model.
static uint16_t oC_Net_ConvertUint16FromNetworkEndianess(uint16_t v)
converts uint16_t from network byte order
oC_Net_Ipv4PacketHeader_t Header
Header of the IPv4 packet.
identifier for allocations
uint32_t DF
Don't Fragment - packet can be fragmented or not
oC_Time_t LeaseTime
IP lease time.
stores network interface informations
oC_Net_MacAddress_t MacAddress
MAC address.
static oC_ErrorCode_t oC_Net_ReadLayerByName(oC_Net_Layer_t *outLayer, const char *Name)
returns network OSI layer according to its name
oC_Net_Protocol_t
stores the protocol number for the IP headers The type is for storing protocol number. The values can be written indirectly to the IP headers.
uint32_t HardwareAddressLength
Number of bytes in the HW address.
The file contains definitions for the compiler, that helps to manage errors, etc. ...
static void oC_Net_Packet_SetAddress(oC_Net_Packet_t *Packet, const oC_Net_Address_t *Source, const oC_Net_Address_t *Destination)
sets addresses in the packet
const oC_Net_Packet_t * ConstPacket
Pointer to the packet to send (for sending)
IPv6 encapsulation protocol.
oC_Net_Ipv6PacketHeader_t Header
Header of the IPv6 packet.
stores status of network queue
char oC_Net_FriendlyInterfaceName_t[MAXIMUM_FRIENDLY_INTERFACE_NAME]
type for storing friendly name string
oC_Net_LinkStatus_t LinkStatus
Network interface link status (UP/DOWN)
oC_Net_AddressType_t
stores type of the network address
static bool oC_Net_IsAddressEmpty(const oC_Net_Address_t *Address)
returns true if the given address is empty
static bool oC_Net_ConvertHeaderToNetworkEndianess(oC_Net_Packet_t *Packet)
converts header to network endianess
static bool oC_Net_Ipv4_IsAddressInSubnet(oC_Net_Ipv4_t IP, oC_Net_Ipv4_t Subnet, oC_Net_Ipv4_t Mask)
checks if the IPv4 address belongs to the given subnetwork
oC_Net_Ipv4_t DnsIP
IP of the local DNS server.
bool Filled
True if the address is filled.
oC_Net_PacketType_t
stores type of the packet
uint32_t NumberOfElementsInRxQueue
Number of elements in queue ready to receive.
An application layer is an abstraction layer that specifies the shared protocols and interface method...
const char * DriverName
Name of the driver that handles the network interface.
char oC_Net_InterfaceName_t[IFNAMSIZ]
stores name of the network interface
uint32_t oC_Net_Ipv4_t
stores IPv4 address
static bool oC_Net_IsAddressInSubnet(const oC_Net_Address_t *Address, const oC_Net_Address_t *Subnet, const oC_Net_Address_t *Mask)
checks if the address is in subnet
static oC_Net_PacketType_t oC_Net_Packet_GetType(const oC_Net_Packet_t *Packet)
returns type of the packet
static oC_ErrorCode_t oC_Net_ReadLayerName(oC_Net_Layer_t Layer, char *outName, oC_MemorySize_t Size)
reads network layer name
static uint16_t oC_Net_GetMaximumPacketDataSize(oC_Net_PacketType_t Type)
returns maximum size of the packet data
oC_Net_HardwareAddress_t Destination
Hardware Destination Address.
uint8_t oC_Net_MacAddress_t[MAC_ADDRESS_LENGTH]
stores MAC address
Transmission Control Protocol.
Mask to get the main layer of the OSI model.
oC_Net_HardwareType_t
stores hardware type of the network interface
oC_Net_Ipv4_t NtpIP
Main Network Time Protocol Server available in the subnetwork.
static uint16_t oC_Net_ConvertUint16ToNetworkEndianess(uint16_t v)
converts uint16_t to network byte order
oC_Net_Ipv4_t Netmask
Local network mask.
static oC_ErrorCode_t oC_Net_HardwareAddressToString(const oC_Net_HardwareAddress_t *HardwareAddress, oC_Net_HardwareType_t Type, char *outString, oC_MemorySize_t Size)
prints HW address to the string
oC_Net_HardwareAddress_t HardwareAddress
Hardware address.
uint8_t DefaultTTL
Default TTL value for the IPv4 packets.
oC_Net_InterfaceName_t InterfaceName
Name of the interface.
oC_Net_Ipv4_t BroadcastIP
IP that should be used for broadcasting.
uint32_t oC_Net_Cost_t
stores cost of the network connection
uint32_t Reserved
This is always 0.
oC_MemorySize_t MTU
MTU (Maximum Transmission Unit) for the local network.
uint8_t Address
Universal HW Address pointer.
oC_BaudRate_t BaudRate
Baud rate of the interface.
Logical link control sublayer - The uppermost sublayer, LLC, multiplexes protocols running atop the d...
uint32_t PayloadLength
Size of the payload in octets (bytes)
uint32_t FragmentOffset
Field to identify position of fragment within original packet.
oC_Net_Ipv4Info_t IPv4
IPv4 informations.
oC_Net_Ipv4_t IPv4
Address in IPv4 version.
uint32_t ID
ID value for reconstruction the packet from segments.
In the seven-layer OSI model of computer networking, the physical layer or layer 1 is the first and l...
Network interface layer - sublayer of the Network layer.
static oC_ErrorCode_t oC_Net_AddressToString(const oC_Net_Address_t *Address, char *outString, oC_MemorySize_t Size)
prints IP to the string
uint16_t Size
Size Data in frame.
uint32_t FlowLabel
Originally created for tracking, now it's only a hint for routers and switches.
static uint32_t oC_Net_ConvertUint32FromNetworkEndianess(uint32_t v)
converts uint32_t from network byte order
oC_Net_HardwareType_t HardwareType
Type of the hardware device.
oC_Timestamp_t IpExpiredTimestamp
Timestamp of IP expiration.
stores informations about the frame to send
static bool oC_Net_ConvertHeaderFromNetworkEndianess(oC_Net_Packet_t *Packet)
converts header from network endianess
uint32_t IHL
4 bits, that contain Internet Header Length, which is the length of the header in multiples of 4 (num...
uint32_t NextHeader
Specifies the type of the next header in the packet (TCP/UDP,etc)
static void oC_Net_Packet_SetData(oC_Net_Packet_t *Packet, const void *Data, uint16_t Size)
sets payload in the packet
MAC may refer to the sublayer that determines who is allowed to access the media at any one time (e...
uint32_t oC_Net_InterfaceIndex_t
stores index of the interface
In the seven-layer OSI model of computer networking, the session layer is layer 5.
oC_Net_Ipv6_t IPv6
Address in IPv6 version.
static const char * oC_Net_GetProtocolName(oC_Net_Protocol_t Protocol)
returns user friendly name of the protocol
struct PACKED oC_Net_Ipv6_t
stores IPv6 address
oC_MemorySize_t ReceivedBytes
Number of received bytes.
Internet Control Message Protocol.
Frame stores IPv6 packet.
static bool oC_Net_IsAddressCorrect(const oC_Net_Address_t *Address)
returns true if the given address is correct
static void oC_Net_ConvertBufferToNetworkEndianess(void *Buffer, uint16_t Size)
converts buffer to network endianess
oC_Net_Ipv6Info_t IPv6
IPv6 informations.
uint64_t LowPart
Low 8 bytes of the IPv6 address.
oC_Net_HardwareAddress_t Source
Hardware Source Address.
static uint32_t oC_Net_ConvertUint32ToNetworkEndianess(uint32_t v)
converts uint32_t to network byte order
static uint16_t oC_Net_GetPacketSize(const oC_Net_Packet_t *Packet, bool WithHeader)
returns size of the packet
static const char * oC_Net_GetHardwareTypeName(oC_Net_HardwareType_t Type)
returns name of the hardware type
uint32_t TTL
Time to live - number of hops the packet is allowed to pass before it dies.
Open Shortest Path First.
uint8_t Data[IPv4_MAXIMUM_DATA_LENGTH]
Data of the packet.
In computer networking, the transport layer is a conceptual division of methods in the layered archit...
oC_Net_Ipv6_t Source
Source IP address.
oC_Net_Ipv4Packet_t IPv4
Packet in format IPv4.
oC_Net_Packet_t * Packet
Pointer to the packet to send.
Static array definitions.
oC_Net_FrameType_t FrameType
Type of the frame.
uint32_t Checksum
Header checksum - number used for errors detection.
static int oC_Net_PrepareInterfaceName(oC_Net_InterfaceName_t *outName, const char *Prefix, oC_Net_InterfaceIndex_t Index)
prepares interface name string
The file with memory manager interface.
static oC_MemorySize_t oC_Net_GetHardwareAddressSize(oC_Net_HardwareType_t Type)
returns size of the hardware address (in bytes)
Frame stores IPv4 packet.
uint32_t NumberOfElementsInTxQueue
Number of elements in queue to send.
Network interface is DOWN (cable is not connected)
static void * oC_Net_Packet_GetDataReference(oC_Net_Packet_t *Packet)
returns reference to the payload in the packet
uint32_t Version
4 bits, that contain the version, that specified if it's an IPv4 or IPv6 packet
static bool oC_Net_IsMainLayer(oC_Net_Layer_t Layer, oC_Net_Layer_t MainLayer)
returns true if Layer is part of the MainLayer
The file with interface for string library.
uint32_t Protocol
Contains selected protocol (TCP/UDP/ICMP,etc).
struct PACKED oC_Net_Ipv4PacketHeader_t
contains IPv4 packet header
Stream Control Transmission Protocol.
uint32_t MF
More Fragments - whether more fragments of a packet follow
static uint16_t oC_Net_CalculateChecksum(const void *Buffer, uint16_t Size, uint16_t InitialValue, bool ConvertEndianess, bool PrepareChecksumToSend)
oC_Net_Ipv6_t IPv6
IP of the network interface.
static const oC_Allocator_t Allocator
static bool oC_Net_Packet_Delete(oC_Net_Packet_t **Packet)
releases memory allocated for a packet
oC_Net_QueueStatus_t QueueStatus
Current status of network interface's queue.
oC_Net_Ipv4_t GatewayIP
Default gateway IP.
oC_Net_Ipv4_t DestinationIp
Destination IP address.
struct PACKED oC_Net_Ipv4Packet_t
stores IPv4 packet
static uint16_t oC_Net_Packet_CalculateChecksum(oC_Net_Packet_t *Packet)
calculates checksum for a packet (it only calculates it and does not fill it!)
static oC_ErrorCode_t oC_Net_Ipv4AddressToString(oC_Net_Ipv4_t Address, char *outString, oC_MemorySize_t Size)
prints IPv4 address to the string
uint16_t oC_Net_Port_t
Port of the network address.
static oC_ErrorCode_t oC_Net_AddressFromString(const char *Address, oC_Net_Address_t *outAddress)
reads IP address from the string
uint32_t TrafficClass
The bits of this field hold two values.
oC_Net_Ipv4_t IP
IP of the network interface.
Network interface is UP (cable is connected)
stores network interface IPv4 informations
oC_Net_HardwareAddress_t HardwareBroadcastAddress
Hardware address that should be used for broadcast.
stores network interface IPv6 informations
oC_Net_LinkStatus_t
stores network interface link status
oC_Net_AddressType_t Type
Type of the address stored inside.
oC_Net_Ipv6Packet_t IPv6
Packet in format IPv6.
struct PACKED oC_Net_Ipv6PacketHeader_t
contains IPv6 packet header
Address resolution packet.
oC_Net_FrameType_t
stores type of the frame
oC_Net_Port_t Port
Port of the address.
oC_Net_Ipv6_t Destination
Destination IP address.
oC_Net_Ipv4_t DhcpIP
IP of the local DHCP server.
oC_Net_HardwareAddress_t HardwareRouterAddress
HW address of the local router.
The file with standard input/output operations.
#define NULL
pointer to a zero
oC_Net_Layer_t
stores layer of the OSI model