/* -*- Mode:C; Tab-width:4 -*- */
/*                                                                       */
/*                                                                       */
/*                      RESTRICTED RIGHTS LEGEND                         */
/*                                                                       */
/* Use, duplication, or disclosure by the Government is subject to       */
/* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in  */
/* Technical Data and Computer Software clause at 252.227-7013.          */
/*                                                                       */
/*                    TEXAS INSTRUMENTS INCORPORATED.                    */
/*                            P.O. BOX 149149                            */
/*                         AUSTIN, TEXAS 78714-9149                      */
/*                              MS 2151                                  */
/*                                                                       */
/*  Copyright (C)   1987,1988,1989,1990 Texas Instruments Incorporated.  */
/*  All rights reserved.                                                 */
/*                                                                       */

/* 08/28/89 clm - the following conditional appears to do nothing, and the 3.0 */
/* C compiler gets an error because of the %%%, so I have removed it.          */
/*
#ifdef %%%SOCKETS%%%
#define %%%SOCKETS%%%
#endif
*/

#include "::bsd:sys:socket.h"
#include <utility.h>

struct micronet_addr
{
	unsigned short	family;
	unsigned short	port;
	unsigned long   slot;
	char	fill[8];
};

struct sock
{
  int allocated;
  int domain;
  int type;
  int proto;
  queue_struct recv_queue;
  struct micronet_addr src_addr;
};

extern int socket_initialize();
extern int socket();
extern int bind();
extern int getsockname();
extern int recvfrom();
extern int sendto();

extern int recvfrom_acb();
extern int sendto_acb();

extern Ptr sendto_acb_allocate();
extern void recvfrom_acb_return();

#define NUMBER_OF_SOCKETS 32
#define EWOULDBLOCK -1


/* This needs to be fixed. It should be set up from a resource at init time. */
#define MICRONETDEV	-51

#define ERROR		-1
#define SOCKET_DEVICE MICRONETDEV

#define NO_PORTS_AVAILABLE -1
#define PORT_ALREADY_IN_USE -1


/* This could be extended later to map to multiple devices for one protocol depending on address. */
#define map_protocol_to_device(socket) SOCKET_DEVICE

#define PORTMAP_CHANNEL 8
#define PORTMAP_PORT 111

/* The array of sockets. */
extern struct sock sockets[];

#define SUCCESS 0 /* Value returned from ioctl calls on success. */

#define ACB_OVERHEAD_BYTE_COUNT 0

/* Definitions needed to support pre release 6 rpc applications. */

struct sock_info
{
  int length;
  int domain;
  int type;
  int protocol;
  int socket;      /* Return value. */
};


struct bind_info
{
  int length;
  int socket;
  struct sockaddr *addr;
  int addrlen;
};

struct sockname_info
{
  int length;
  int socket;
  struct sockaddr *addr;
  int *addrlen;
};

struct send_info
{
  int length;
  int socket;
  char *buf;
  int buflen;
  int flags;
  struct sockaddr *addr;
  int addrlen;
};


struct recv_info
{
  int length;
  int socket;
  char *buf;
  int buflen;
  int flags;
  struct sockaddr *addr;
  int *addrlen;
  int nbytes;            /* Return value. */
};

struct close_info
{
  int socket;
};

#define SIOCSOCK	'S'<<8 | 0
#define SIOCBIND	'S'<<8 | 1
#define SIOCCONN	'S'<<8 | 2
#define SIOCACPT	'S'<<8 | 3
#define SIOCLSTN	'S'<<8 | 4
#define SIOCRECV	'S'<<8 | 5
#define SIOCSEND	'S'<<8 | 6
#define SIOCPEER	'S'<<8 | 7
#define SIOCNAME	'S'<<8 | 8
#define SIOCGOPT	'S'<<8 | 9
#define SIOCSOPT	'S'<<8 | 10
#define SIOCSHUT	'S'<<8 | 11
#define SIOCSLCT	'S'<<8 | 12
#define SIOCSMSG    'S'<<8 | 13
#define SIOCGMSG    'S'<<8 | 14
#define SIOCCLOSE   'S'<<8 | 15
#define SELECT_WORD_LOC 5        /* Also defined in micronet-device.h. */ 
