Choco OS  V.0.16.9.0
Join to the chocolate world
oc_icmp.c
Go to the documentation of this file.
1 
27 #include <oc_icmp.h>
28 #include <oc_module.h>
29 #include <oc_intman.h>
30 #include <oc_mutex.h>
31 #include <oc_netifman.h>
32 
38 #define _________________________________________TYPES_SECTION______________________________________________________________________________
39 
40 typedef struct
41 {
42  oC_Icmp_Type_t Type;
43  oC_Process_t Process;
44  oC_Mutex_t Busy;
46 
47 typedef struct
48 {
49  oC_Icmp_Packet_t* Packet;
50  oC_Netif_t Netif;
52 
53 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
54 
60 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
61 
63 static uint16_t CalculateChecksum ( oC_Icmp_Packet_t * Packet );
64 static bool PacketFilterFunction ( oC_Icmp_Packet_t * ReceivedPacket , oC_Icmp_Type_t * ExpectedType , oC_Netif_t Netif );
65 
66 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
67 
73 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
74 
75 static oC_List(ReservationData_t*) ReservedTypes = NULL;
76 static oC_Event_t TypeReleased = NULL;
77 static oC_Mutex_t ModuleBusy = NULL;
78 static const oC_Allocator_t Allocator = {
79  .Name = "icmp-module"
80 };
81 
82 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
83 
89 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
90 
91 //==========================================================================================================================================
108 //==========================================================================================================================================
109 oC_ErrorCode_t oC_Icmp_TurnOn( void )
110 {
111  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
112 
113  oC_IntMan_EnterCriticalSection();
114  if(
115  oC_Module_TurnOffVerification(&errorCode, oC_Module_Icmp)
116  )
117  {
118  ReservedTypes = oC_List_New(&Allocator, AllocationFlags_Default);
119  TypeReleased = oC_Event_New( oC_Event_State_Inactive, &Allocator, AllocationFlags_Default );
120  ModuleBusy = oC_Mutex_New( oC_Mutex_Type_Normal , &Allocator, AllocationFlags_Default);
121 
122  if(
123  ErrorCondition( ReservedTypes != NULL , oC_ErrorCode_AllocationError )
124  && ErrorCondition( ModuleBusy != NULL , oC_ErrorCode_AllocationError )
125  && ErrorCondition( TypeReleased != NULL , oC_ErrorCode_AllocationError )
126  )
127  {
128  oC_Module_TurnOn(oC_Module_Icmp);
129  errorCode = oC_ErrorCode_None;
130  }
131  else
132  {
133  bool listDeleted = oC_List_Delete( TypeReleased , AllocationFlags_Default);
134  bool mutexDeleted = oC_Mutex_Delete(&ModuleBusy , AllocationFlags_Default);
135  bool eventDeleted = oC_Event_Delete(&TypeReleased , AllocationFlags_Default);
136 
137  oC_SaveIfFalse("ICMP:TurnOn - Cannot delete list " , listDeleted , oC_ErrorCode_ReleaseError );
138  oC_SaveIfFalse("ICMP:TurnOn - Cannot delete mutex " , mutexDeleted , oC_ErrorCode_ReleaseError );
139  oC_SaveIfFalse("ICMP:TurnOn - Cannot delete event" , eventDeleted , oC_ErrorCode_ReleaseError );
140  }
141  }
142  oC_IntMan_ExitCriticalSection();
143 
144  return errorCode;
145 }
146 
147 //==========================================================================================================================================
164 //==========================================================================================================================================
165 oC_ErrorCode_t oC_Icmp_TurnOff( void )
166 {
167  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
168 
169  oC_IntMan_EnterCriticalSection();
170  if(
171  oC_Module_TurnOnVerification(&errorCode , oC_Module_Icmp)
172  )
173  {
174  oC_Module_TurnOff(oC_Module_Icmp);
175 
176  bool allPacketsReleased = true;
177 
178  bool listDeleted = oC_List_Delete ( ReservedTypes , AllocationFlags_Default );
179  bool eventDeleted = oC_Event_Delete( &TypeReleased , AllocationFlags_Default );
180  bool mutexDeleted = oC_Mutex_Delete( &ModuleBusy , AllocationFlags_Default );
181 
182  if(
183  ErrorCondition( listDeleted , oC_ErrorCode_ReleaseError )
184  && ErrorCondition( allPacketsReleased , oC_ErrorCode_ReleaseError )
185  && ErrorCondition( eventDeleted , oC_ErrorCode_ReleaseError )
186  && ErrorCondition( mutexDeleted , oC_ErrorCode_ReleaseError )
187  && ErrorCondition( oC_MemMan_FreeAllMemoryOfAllocator(&Allocator) , oC_ErrorCode_ReleaseError )
188  )
189  {
190  errorCode = oC_ErrorCode_None;
191  }
192  }
193  oC_IntMan_ExitCriticalSection();
194 
195  return errorCode;
196 }
197 
198 //==========================================================================================================================================
210 //==========================================================================================================================================
212 {
213  bool reserved = false;
214 
215  if(
216  oC_Module_IsTurnedOn(oC_Module_Icmp)
217  && oC_SaveIfFalse("UDP::IsPortReserved - ", Type != oC_Icmp_Type_Empty , oC_ErrorCode_TypeNotCorrect )
218  && oC_SaveIfFalse("UDP::IsPortReserved - ", Process == NULL || oC_Process_IsCorrect(Process) , oC_ErrorCode_ProcessNotCorrect )
219  )
220  {
221  ReservationData_t * reservation = FindReservation(Type,Process);
222  reserved = reservation != NULL;
223  }
224 
225  return reserved;
226 }
227 //==========================================================================================================================================
251 //==========================================================================================================================================
252 oC_ErrorCode_t oC_Icmp_ReserveType( oC_Icmp_Type_t Type , oC_Time_t Timeout )
253 {
254  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
255 
256  if(
257  oC_Module_TurnOnVerification(&errorCode, oC_Module_Icmp)
258  && ErrorCondition( Type >= 0 , oC_ErrorCode_TypeNotCorrect )
259  && ErrorCondition( Timeout >= 0 , oC_ErrorCode_TimeNotCorrect )
260  )
261  {
262  oC_Timestamp_t endTimestamp = oC_KTime_GetTimestamp() + Timeout;
263 
264  while(oC_KTime_GetTimestamp() <= endTimestamp)
265  {
266  if( ErrorCondition( oC_Mutex_Take(ModuleBusy, oC_KTime_CalculateTimeout(endTimestamp)) , oC_ErrorCode_ModuleBusy ) )
267  {
268  if( ErrorCondition( oC_Icmp_IsTypeReserved(Type,NULL) == false , oC_ErrorCode_TypeBusy ))
269  {
270  ReservationData_t * reservation = kmalloc( sizeof(ReservationData_t), &Allocator, AllocationFlags_Default );
271 
272  if(ErrorCondition( reservation != NULL , oC_ErrorCode_AllocationError ))
273  {
274  reservation->Busy = oC_Mutex_New( oC_Mutex_Type_Normal , &Allocator, AllocationFlags_Default );
275 
276  if( ErrorCondition( reservation->Busy != NULL , oC_ErrorCode_AllocationError ) )
277  {
278  reservation->Type = Type;
279  reservation->Process = getcurprocess();
280 
281  bool addedToList = oC_List_PushBack(ReservedTypes, reservation, &Allocator);
282 
283  if( ErrorCondition( addedToList, oC_ErrorCode_CannotAddObjectToList ) )
284  {
285  errorCode = oC_ErrorCode_None;
286  }
287  else
288  {
289  oC_SaveIfFalse("ICMP:Reserve - cannot release reservation memory ", kfree(reservation, AllocationFlags_Default), oC_ErrorCode_ReleaseError);
290  }
291  }
292  else
293  {
294  oC_SaveIfFalse("ICMP:Reserve - cannot release reservation memory ", kfree(reservation, AllocationFlags_Default), oC_ErrorCode_ReleaseError);
295  }
296 
297  }
298 
299  oC_Mutex_Give(ModuleBusy);
300  break;
301  }
302  else
303  {
304  oC_Mutex_Give(ModuleBusy);
305 
306  if(oC_Event_WaitForState(TypeReleased,Type,oC_Event_StateMask_Full, oC_KTime_CalculateTimeout(endTimestamp)) == false)
307  {
308  errorCode = oC_ErrorCode_Timeout;
309  break;
310  }
311  }
312  }
313  }
314  }
315 
316  return errorCode;
317 }
318 //==========================================================================================================================================
346 //==========================================================================================================================================
347 oC_ErrorCode_t oC_Icmp_ReleaseType( oC_Icmp_Type_t Type , oC_Time_t Timeout )
348 {
349  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
350  oC_Timestamp_t endTimestamp = oC_KTime_GetTimestamp() + Timeout;
351 
352  if(
353  oC_Module_TurnOnVerification( &errorCode , oC_Module_Udp )
354  && ErrorCondition( Timeout >= 0 , oC_ErrorCode_TimeNotCorrect )
355  && ErrorCondition( oC_Mutex_Take(ModuleBusy,Timeout) , oC_ErrorCode_ModuleBusy )
356  )
357  {
358  ReservationData_t * reservation = FindReservation(Type,NULL);
359 
360  if(
361  ErrorCondition( reservation != NULL , oC_ErrorCode_TypeNotReserved )
362  && ErrorCondition( reservation->Process == getcurprocess() , oC_ErrorCode_TypeReservedByDifferentProcess )
363  && ErrorCondition( oC_Mutex_Take(reservation->Busy,oC_KTime_CalculateTimeout(endTimestamp)) , oC_ErrorCode_TypeBusy )
364  )
365  {
366  bool mutexDeleted = oC_Mutex_Delete(&reservation->Busy, AllocationFlags_Default);
367  bool deletedFromList = oC_List_RemoveAll(ReservedTypes,reservation);
368  bool deleted = kfree(reservation,AllocationFlags_Default);
369 
370  if(
371  ErrorCondition( mutexDeleted , oC_ErrorCode_CannotDeleteObject )
372  && ErrorCondition( deletedFromList , oC_ErrorCode_CannotRemoveObjectFromList )
373  && ErrorCondition( deleted , oC_ErrorCode_ReleaseError )
374  )
375  {
376  oC_Event_SetState(TypeReleased,Type);
377  errorCode = oC_ErrorCode_None;
378  }
379  }
380 
381  oC_Mutex_Give(ModuleBusy);
382  }
383 
384  return errorCode;
385 }
386 //==========================================================================================================================================
413 //==========================================================================================================================================
414 oC_ErrorCode_t oC_Icmp_ReleaseAllTypesReservedBy( oC_Process_t Process , oC_Time_t Timeout )
415 {
416  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
417  oC_Timestamp_t endTimestamp = oC_KTime_GetTimestamp() + Timeout;
418 
419  if(
420  oC_Module_TurnOnVerification( &errorCode, oC_Module_Udp )
421  && ErrorCondition( getcuruser() == getrootuser() , oC_ErrorCode_PossibleOnlyForRoot )
422  && ErrorCondition( Timeout >= 0 , oC_ErrorCode_TimeNotCorrect )
423  && ErrorCondition( oC_Mutex_Take(ModuleBusy,Timeout) , oC_ErrorCode_ModuleBusy )
424  )
425  {
426  ReservationData_t * reservation = FindReservation(oC_Icmp_Type_Empty, Process);
427 
428  errorCode = oC_ErrorCode_None;
429 
430  while(
431  reservation != NULL
432  && ErrorCondition( oC_KTime_GetTimestamp() <= endTimestamp , oC_ErrorCode_Timeout )
433  )
434  {
435  reservation->Process = getcurprocess();
436 
437  ErrorCode( oC_Icmp_ReleaseType( reservation->Type, oC_KTime_CalculateTimeout(endTimestamp) ) );
438 
439  reservation = FindReservation( oC_Icmp_Type_Empty, Process );
440  }
441 
442  oC_Mutex_Give(ModuleBusy);
443  }
444 
445  return errorCode;
446 }
447 
448 //==========================================================================================================================================
468 //==========================================================================================================================================
469 oC_ErrorCode_t oC_Icmp_CalculateChecksum( oC_Icmp_Packet_t * Packet , uint16_t * outChecksum )
470 {
471  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
472 
473  if(
474  oC_Module_TurnOnVerification(&errorCode , oC_Module_Udp)
475  && ErrorCondition( isram(Packet) , oC_ErrorCode_AddressNotInRam )
476  && ErrorCondition( isram(outChecksum) , oC_ErrorCode_OutputAddressNotInRAM )
477  )
478  {
480 
481  if( ErrorCondition(isram(datagram), oC_ErrorCode_PacketNotCorrect) )
482  {
483  *outChecksum = CalculateChecksum(Packet);
484  errorCode = oC_ErrorCode_None;
485  }
486  }
487 
488  return errorCode;
489 }
490 
491 //==========================================================================================================================================
512 //==========================================================================================================================================
513 oC_Icmp_Packet_t* oC_Icmp_Packet_New( Allocator_t PacketAllocator , oC_Net_PacketType_t Type , oC_Icmp_Type_t IcmpType , uint8_t Code , const void * Data , uint16_t Size )
514 {
515  oC_Icmp_Packet_t * packet = NULL;
516  uint16_t packetSize = Size + sizeof(oC_Icmp_Header_t);
517 
518  if(
519  oC_SaveIfFalse("Icmp::PacketNew: " , oC_Module_IsTurnedOn(oC_Module_Icmp) , oC_ErrorCode_ModuleNotStartedYet )
520  && oC_SaveIfFalse("Icmp::PacketNew: Packet Type incorrect - " , Type == oC_Net_PacketType_IPv4
521  || Type == oC_Net_PacketType_IPv6 , oC_ErrorCode_TypeNotCorrect )
522  && oC_SaveIfFalse("Icmp::PacketNew: Size is not correct - " , Size > 0 , oC_ErrorCode_SizeNotCorrect )
523  && oC_SaveIfFalse("Icmp::PacketNew: Data address incorrect - " , Data == NULL || isaddresscorrect(Data) , oC_ErrorCode_WrongAddress )
524  && oC_SaveIfFalse("Icmp::PacketNew: Allocator incorrect - " , isaddresscorrect(PacketAllocator) , oC_ErrorCode_AllocatorNotCorrect )
525  )
526  {
527  packet = (oC_Icmp_Packet_t*) oC_Net_Packet_New( PacketAllocator, Type, NULL, packetSize );
528 
529  if(oC_SaveIfFalse("Icmp::PacketNew: Cannot allocate memory for a packet - ", packet != NULL , oC_ErrorCode_AllocationError))
530  {
532 
533  datagram->Header.Type = IcmpType;
534  datagram->Header.Code = Code;
535 
536  if(Data != NULL)
537  {
538  void * dataDestination = datagram;
539 
540  dataDestination += sizeof(oC_Icmp_Header_t);
541 
542  memcpy(dataDestination,Data,Size);
543  }
544  }
545  }
546 
547  return packet;
548 }
549 
550 //==========================================================================================================================================
554 //==========================================================================================================================================
555 bool oC_Icmp_Packet_SetSize( oC_Icmp_Packet_t * Packet , uint16_t Size )
556 {
557  bool success = false;
558  uint16_t packetSize = Size + sizeof(oC_Icmp_Header_t);
559 
560  if(
561  oC_SaveIfFalse("ICMP::SetSize - " , isram(Packet) , oC_ErrorCode_AddressNotInRam )
562  && oC_SaveIfFalse("ICMP::SetSize - " , Size > 0 , oC_ErrorCode_SizeNotCorrect )
563  && oC_SaveIfFalse("ICMP::SetSize - " , packetSize > Size , oC_ErrorCode_SizeTooBig )
564  )
565  {
566  success = oC_Net_Packet_SetSize(&Packet->Packet,packetSize);
567  }
568 
569  return success;
570 }
571 
572 //==========================================================================================================================================
576 //==========================================================================================================================================
578 {
579  bool success = false;
580 
581  if(isram(Packet) && isram(*Packet))
582  {
583  success = kfree(*Packet,AllocationFlags_Default);
584  *Packet = NULL;
585  }
586 
587  return success;
588 }
589 //==========================================================================================================================================
593 //==========================================================================================================================================
595 {
596  void * data = NULL;
598 
599  if(isaddresscorrect(datagram))
600  {
601  data = &datagram->Message;
602  }
603 
604  return data;
605 }
606 
607 //==========================================================================================================================================
641 //==========================================================================================================================================
642 oC_ErrorCode_t oC_Icmp_Send( oC_Netif_t Netif , const oC_Net_Address_t * Destination , oC_Icmp_Packet_t * Packet , oC_Time_t Timeout )
643 {
644  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
645  oC_Timestamp_t timestamp = oC_KTime_GetTimestamp();
646  oC_Timestamp_t endTimestamp = timestamp + Timeout;
647 
648  if(oC_Module_TurnOnVerification(&errorCode, oC_Module_Icmp))
649  {
650  if(
651  ErrorCondition( Netif == NULL || oC_Netif_IsCorrect(Netif) , oC_ErrorCode_NetifNotCorrect )
652  && ErrorCondition( isaddresscorrect(Destination) , oC_ErrorCode_WrongAddress )
653  && ErrorCondition( oC_Net_IsAddressCorrect(Destination) , oC_ErrorCode_IpAddressNotCorrect )
654  && ErrorCondition( isram(Packet) , oC_ErrorCode_AddressNotInRam )
655  && ErrorCondition( Timeout >= 0 , oC_ErrorCode_TimeNotCorrect )
656  )
657  {
660  oC_Net_AddressType_t addressType = Destination->Type ;
661 
662  Netif = Netif == NULL ? oC_NetifMan_GetNetifForAddress(Destination) : Netif;
663 
664  if(
665  ErrorCondition( oC_Netif_IsCorrect(Netif) , oC_ErrorCode_CannotFindNetifForTheAddress )
666  && ErrorCondition( datagram != NULL , oC_ErrorCode_PacketNotCorrect )
667  && ErrorCondition( ((oC_Net_PacketType_t)addressType) == packetType , oC_ErrorCode_TypeNotCorrect )
668  )
669  {
670  if(packetType == oC_Net_PacketType_IPv4)
671  {
672  Packet->Packet.IPv4.Header.DF = 0;
673  Packet->Packet.IPv4.Header.DestinationIp = Destination->IPv4;
675  Packet->Packet.IPv4.Header.FragmentOffset = 0;
676  Packet->Packet.IPv4.Header.ID = 0;
677  Packet->Packet.IPv4.Header.IHL = 5;
678  Packet->Packet.IPv4.Header.MF = 0;
680  Packet->Packet.IPv4.Header.QoS = 0;
681  Packet->Packet.IPv4.Header.TTL = 0xFF;
682  Packet->Packet.IPv4.Header.Checksum = 0;
683 
684  }
685  else
686  {
687  memcpy(&Packet->Packet.IPv6.Header.Destination,&Destination->IPv6,sizeof(oC_Net_Ipv6_t));
689 
690  oC_SaveError("UDP::Send - Function is not implemented for IPv6!", oC_ErrorCode_NotImplemented);
691  }
692 
693  datagram->Header.Checksum = 0;
694  datagram->Header.Checksum = CalculateChecksum(Packet);
695 
696  errorCode = oC_Netif_SendPacket( Netif, &Packet->Packet, oC_KTime_CalculateTimeout(endTimestamp) );
697  }
698  }
699  }
700 
701  return errorCode;
702 }
703 
704 //==========================================================================================================================================
741 //==========================================================================================================================================
742 oC_ErrorCode_t oC_Icmp_Receive( oC_Netif_t Netif , oC_Icmp_Packet_t * outPacket , oC_Icmp_Type_t Type , oC_Time_t Timeout )
743 {
744  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
745  oC_Timestamp_t endTimestamp = oC_KTime_GetTimestamp() + Timeout;
746 
747  if(oC_Module_TurnOnVerification(&errorCode, oC_Module_Icmp))
748  {
749  if(
750  ErrorCondition( Netif == NULL || oC_Netif_IsCorrect(Netif) , oC_ErrorCode_NetifNotCorrect )
751  && ErrorCondition( isram(outPacket) , oC_ErrorCode_OutputAddressNotInRAM )
752  && ErrorCondition( Timeout >= 0 , oC_ErrorCode_TimeNotCorrect )
753  && ErrorCondition( oC_Mutex_Take(ModuleBusy,oC_KTime_CalculateTimeout(endTimestamp)) , oC_ErrorCode_ModuleBusy )
754  )
755  {
756  oC_Mutex_Give(ModuleBusy); // It is taken only to ensure, that there is not any important operation in progress
757 
758  ReservationData_t * reservation = FindReservation( Type , NULL );
759 
760  if(
761  ErrorCondition( reservation != NULL , oC_ErrorCode_TypeNotReserved )
762  && ErrorCondition( reservation->Process == getcurprocess() , oC_ErrorCode_TypeReservedByDifferentProcess )
763  && ErrorCondition( oC_Mutex_Take( reservation->Busy , oC_KTime_CalculateTimeout(endTimestamp) ) , oC_ErrorCode_TypeBusy )
764  )
765  {
766  oC_Netif_t receivedNetif = NULL;
767  oC_Net_Address_t addressFilter;
768 
769  memset(&addressFilter, 0 , sizeof(addressFilter));
770 
771  addressFilter.Protocol = oC_Net_Protocol_ICMP;
772 
773  if( ErrorCode( oC_NetifMan_ReceivePacket(&addressFilter, &outPacket->Packet, oC_KTime_CalculateTimeout(endTimestamp), &receivedNetif, (oC_NetifMan_PacketFilterFunction_t)PacketFilterFunction, &Type) ) )
774  {
775  errorCode = oC_ErrorCode_None;
776  }
777 
778  oC_Mutex_Give(reservation->Busy);
779  }
780 
781  }
782  }
783 
784  return errorCode;
785 }
786 
787 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
788 
794 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
795 
796 //==========================================================================================================================================
800 //==========================================================================================================================================
802 {
803  ReservationData_t * foundReservation = NULL;
804 
805  foreach(ReservedTypes,reservation)
806  {
807  if(
808  (reservation->Type == Type && Type != oC_Icmp_Type_Empty )
809  || (reservation->Process == Process && Process != NULL )
810  )
811  {
812  foundReservation = reservation;
813  }
814  }
815 
816  return foundReservation;
817 }
818 
819 //==========================================================================================================================================
823 //==========================================================================================================================================
824 static uint16_t CalculateChecksum( oC_Icmp_Packet_t * Packet )
825 {
826  uint32_t checksum = 0;
827  uint16_t size = oC_Net_GetPacketSize(&Packet->Packet,false);
829  uint16_t savedChecksum = datagram->Header.Checksum;
830 
831  datagram->Header.Checksum = 0;
832 
833  checksum = oC_Net_CalculateChecksum(datagram,size,0,false,true);
834 
835  datagram->Header.Checksum = savedChecksum;
836 
837  return (uint16_t)checksum;
838 }
839 
840 //==========================================================================================================================================
844 //==========================================================================================================================================
845 static bool PacketFilterFunction( oC_Icmp_Packet_t * ReceivedPacket , oC_Icmp_Type_t * ExpectedType , oC_Netif_t Netif )
846 {
847  bool expected = false;
848 
849  if(isram(ReceivedPacket) && isaddresscorrect(ExpectedType))
850  {
851  expected = ReceivedPacket->IPv4.IcmpDatagram.Header.Type == (*ExpectedType);
852  }
853 
854  return expected;
855 }
856 
857 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
858 
oC_Net_Ipv4_t SourceIp
Source IP address.
Definition: oc_net.h:231
static bool oC_Net_Packet_SetSize(oC_Net_Packet_t *Packet, uint16_t Size)
sets size of the packet
Definition: oc_net.h:1388
oC_ErrorCode_t oC_Icmp_Send(oC_Netif_t Netif, const oC_Net_Address_t *Destination, oC_Icmp_Packet_t *Packet, oC_Time_t Timeout)
sends ICMP packet
Definition: oc_icmp.c:642
Packet in type IPv4.
Definition: oc_net.h:177
bool oC_Event_WaitForState(oC_Event_t Event, oC_Event_State_t State, oC_Event_StateMask_t StateMask, oC_Time_t Timeout)
Definition: oc_event.c:245
stores ICMP datagram
Definition: oc_icmp.h:145
bool oC_Icmp_IsTypeReserved(oC_Icmp_Type_t Type, oC_Process_t Process)
checks if the given ICMP type is reserved
Definition: oc_icmp.c:211
uint32_t QoS
Quality of Service or Type of Service - describes the priority of the packet
Definition: oc_net.h:221
oC_Net_Protocol_t Protocol
IP Protocol.
Definition: oc_net.h:449
const char * Name
Definition: oc_stdlib.h:161
stores ICMP message header
Definition: oc_icmp.h:82
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
Definition: oc_net.h:1511
static ReservationData_t * FindReservation(oC_Icmp_Type_t Type, oC_Process_t Process)
finds reservation of port or process
Definition: oc_icmp.c:801
oC_Net_Ipv4PacketHeader_t Header
Header of the IPv4 packet.
Definition: oc_net.h:276
identifier for allocations
Definition: oc_stdlib.h:159
uint16_t Checksum
Checksum with ICMP header and Data (with 0 for this field)
Definition: oc_icmp.h:86
uint32_t DF
Don&#39;t Fragment - packet can be fragmented or not
Definition: oc_net.h:226
bool oC_MemMan_FreeAllMemoryOfAllocator(Allocator_t Allocator)
release all memory of allocator
Definition: oc_memman.c:985
oC_ErrorCode_t oC_NetifMan_ReceivePacket(const oC_Net_Address_t *Address, oC_Net_Packet_t *outPacket, oC_Time_t Timeout, oC_Netif_t *outNetif, oC_NetifMan_PacketFilterFunction_t FilterFunction, const void *Parameter)
receives packet from the network
Definition: oc_netifman.c:763
oC_Net_Packet_t Packet
IP packet.
Definition: oc_icmp.h:165
Packet in type IPv6.
Definition: oc_net.h:178
stores ICMP packet (datagram + IP header)
Definition: oc_icmp.h:163
oC_Icmp_Type_t
stores ICMP message type
Definition: oc_icmp.h:55
Stores interface of netif manager module.
stores network address
Definition: oc_net.h:441
oC_Net_AddressType_t
stores type of the network address
Definition: oc_net.h:427
static bool PacketFilterFunction(oC_Icmp_Packet_t *ReceivedPacket, oC_Icmp_Type_t *ExpectedType, oC_Netif_t Netif)
checks if the packet that we received is that we expect
Definition: oc_icmp.c:845
void * oC_Icmp_Packet_GetMessageReference(oC_Icmp_Packet_t *Packet)
returns reference to the message inside ICMP packet
Definition: oc_icmp.c:594
oC_Net_PacketType_t
stores type of the packet
Definition: oc_net.h:174
oC_Icmp_Datagram_t IcmpDatagram
ICMP data in the IPv4 packet.
Definition: oc_icmp.h:170
bool oC_Netif_IsCorrect(oC_Netif_t Netif)
checks if the Netif object is correct
Definition: oc_netif.c:351
static oC_Net_PacketType_t oC_Net_Packet_GetType(const oC_Net_Packet_t *Packet)
returns type of the packet
Definition: oc_net.h:1370
oC_ErrorCode_t oC_Icmp_Receive(oC_Netif_t Netif, oC_Icmp_Packet_t *outPacket, oC_Icmp_Type_t Type, oC_Time_t Timeout)
receives ICMP packet
Definition: oc_icmp.c:742
oC_ErrorCode_t oC_Icmp_CalculateChecksum(oC_Icmp_Packet_t *Packet, uint16_t *outChecksum)
Calculates checksum for ICMP packet.
Definition: oc_icmp.c:469
The file with interface for the module library.
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
Definition: oc_module.h:121
bool oC_Icmp_Packet_Delete(oC_Icmp_Packet_t **Packet)
release memory allocated for a ICMP packet
Definition: oc_icmp.c:577
oC_Net_Ipv4_t oC_Netif_GetIpv4Address(oC_Netif_t Netif)
returns address of the network interface
Definition: oc_netif.c:1427
uint32_t FragmentOffset
Field to identify position of fragment within original packet.
Definition: oc_net.h:224
oC_Icmp_Packet_t * oC_Icmp_Packet_New(Allocator_t PacketAllocator, oC_Net_PacketType_t Type, oC_Icmp_Type_t IcmpType, uint8_t Code, const void *Data, uint16_t Size)
allocates memory for a ICMP packet
Definition: oc_icmp.c:513
uint8_t Type
Type of the ICMP message.
Definition: oc_icmp.h:84
stores network packet
Definition: oc_net.h:302
oC_Net_Ipv4_t IPv4
Address in IPv4 version.
Definition: oc_net.h:446
uint32_t ID
ID value for reconstruction the packet from segments.
Definition: oc_net.h:223
oC_ErrorCode_t oC_Icmp_ReserveType(oC_Icmp_Type_t Type, oC_Time_t Timeout)
reserves a ICMP type
Definition: oc_icmp.c:252
The file with interface for interrupt manager.
bool(* oC_NetifMan_PacketFilterFunction_t)(oC_Net_Packet_t *ReceivedPacket, const void *Parameter, oC_Netif_t Netif)
stores pointer to the function to filter packets
Definition: oc_netifman.h:78
uint32_t IHL
4 bits, that contain Internet Header Length, which is the length of the header in multiples of 4 (num...
Definition: oc_net.h:220
oC_Net_Ipv6_t IPv6
Address in IPv6 version.
Definition: oc_net.h:447
Internet Control Message Protocol.
Definition: oc_net.h:157
static bool oC_Net_IsAddressCorrect(const oC_Net_Address_t *Address)
returns true if the given address is correct
Definition: oc_net.h:918
The file with interface for mutex managing.
static uint16_t oC_Net_GetPacketSize(const oC_Net_Packet_t *Packet, bool WithHeader)
returns size of the packet
Definition: oc_net.h:1076
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
oC_Icmp_Header_t Header
Header of the ICMP packet.
Definition: oc_icmp.h:147
uint32_t TTL
Time to live - number of hops the packet is allowed to pass before it dies.
Definition: oc_net.h:228
oC_Net_Ipv6_t Source
Source IP address.
Definition: oc_net.h:257
oC_Net_Ipv4Packet_t IPv4
Packet in format IPv4.
Definition: oc_net.h:304
oC_ErrorCode_t oC_Icmp_TurnOff(void)
turns off ICMP module
Definition: oc_icmp.c:165
uint32_t Checksum
Header checksum - number used for errors detection.
Definition: oc_net.h:230
oC_Netif_t oC_NetifMan_GetNetifForAddress(const oC_Net_Address_t *Destination)
returns network interface according to destination address
Definition: oc_netifman.c:415
static void * oC_Net_Packet_GetDataReference(oC_Net_Packet_t *Packet)
returns reference to the payload in the packet
Definition: oc_net.h:1419
uint32_t Protocol
Contains selected protocol (TCP/UDP/ICMP,etc).
Definition: oc_net.h:229
oC_ErrorCode_t oC_Icmp_TurnOn(void)
turns on ICMP module
Definition: oc_icmp.c:109
uint32_t MF
More Fragments - whether more fragments of a packet follow
Definition: oc_net.h:225
static uint16_t oC_Net_CalculateChecksum(const void *Buffer, uint16_t Size, uint16_t InitialValue, bool ConvertEndianess, bool PrepareChecksumToSend)
Definition: oc_net.h:1581
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
static const oC_Allocator_t Allocator
Definition: oc_eth.c:152
static uint16_t CalculateChecksum(oC_Icmp_Packet_t *Packet)
calculates checksum for a packet
Definition: oc_icmp.c:824
File with interface for ICMP.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
Definition: oc_module.h:138
oC_ErrorCode_t oC_Netif_SendPacket(oC_Netif_t Netif, oC_Net_Packet_t *Packet, oC_Time_t Timeout)
sends packet by using the network interface
Definition: oc_netif.c:572
oC_Net_Ipv4_t DestinationIp
Destination IP address.
Definition: oc_net.h:232
uint8_t Code
Sub type of the ICMP message.
Definition: oc_icmp.h:85
bool oC_Netif_ReadIpv6Address(oC_Netif_t Netif, oC_Net_Ipv6_t *outAddress)
reads IPv6 address of the network interface
Definition: oc_netif.c:1445
oC_ErrorCode_t oC_Icmp_ReleaseAllTypesReservedBy(oC_Process_t Process, oC_Time_t Timeout)
releases all types reserved by the process
Definition: oc_icmp.c:414
oC_Net_AddressType_t Type
Type of the address stored inside.
Definition: oc_net.h:443
oC_Net_Ipv6Packet_t IPv6
Packet in format IPv6.
Definition: oc_net.h:305
oC_Net_Ipv6_t Destination
Destination IP address.
Definition: oc_net.h:258
oC_ErrorCode_t oC_Icmp_ReleaseType(oC_Icmp_Type_t Type, oC_Time_t Timeout)
releases a type
Definition: oc_icmp.c:347
bool oC_Icmp_Packet_SetSize(oC_Icmp_Packet_t *Packet, uint16_t Size)
sets size of the packet
Definition: oc_icmp.c:555
stores IPv6 address
Definition: oc_net.h:142
#define NULL
pointer to a zero
Definition: oc_null.h:37
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Definition: oc_module.h:185