* - UDP Handling
*/
#include "ipstack.h"
-#include <tpl_drv_common.h>
+#include <api_drv_common.h>
#include "udp.h"
#define UDP_ALLOC_BASE 0xC000
void UDP_Initialise();
void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer);
-void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, void *Address, Uint16 Port, void *Data, size_t Length);
+void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, Uint16 Port, const void *Data, size_t Length);
// --- Client Channels
tVFS_Node *UDP_Channel_Init(tInterface *Interface);
Uint64 UDP_Channel_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
-Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
+Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer);
int UDP_Channel_IOCtl(tVFS_Node *Node, int ID, void *Data);
void UDP_Channel_Close(tVFS_Node *Node);
// --- Helpers
void UDP_int_FreePort(Uint16 Port);
// === GLOBALS ===
+tVFS_NodeType gUDP_NodeType = {
+ .Read = UDP_Channel_Read,
+ .Write = UDP_Channel_Write,
+ .IOCtl = UDP_Channel_IOCtl,
+ .Close = UDP_Channel_Close
+};
tMutex glUDP_Channels;
tUDPChannel *gpUDP_Channels;
* \param Data Packet data
* \param Length Length in bytes of packet data
*/
-void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, void *Address, Uint16 Port, void *Data, size_t Length)
+void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, Uint16 Port, const void *Data, size_t Length)
{
tUDPHeader *hdr;
new->Node.ImplPtr = new;
new->Node.NumACLs = 1;
new->Node.ACLs = &gVFS_ACL_EveryoneRW;
- new->Node.Read = UDP_Channel_Read;
- new->Node.Write = UDP_Channel_Write;
- new->Node.IOCtl = UDP_Channel_IOCtl;
- new->Node.Close = UDP_Channel_Close;
+ new->Node.Type = &gUDP_NodeType;
Mutex_Acquire(&glUDP_Channels);
new->Next = gpUDP_Channels;
/**
* \brief Write to the channel file (send a packet)
*/
-Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer)
{
tUDPChannel *chan = Node->ImplPtr;
- tUDPEndpoint *ep;
- void *data;
+ const tUDPEndpoint *ep;
+ const void *data;
int ofs;
if(chan->LocalPort == 0) return 0;
ep = Buffer;
ofs = 2 + 2 + IPStack_GetAddressSize( ep->AddrType );
- data = (char*)Buffer + ofs;
+ data = (const char *)Buffer + ofs;
UDP_SendPacketTo(chan, ep->AddrType, &ep->Addr, ep->Port, data, (size_t)Length - ofs);