Пример #1
0
struct protosw *  
pffindproto(int domain, int protocol, int type)
{
#ifdef IP_RAW
   if (type == SOCK_RAW)
      return(pffindtype(domain, type));
#endif

   switch (protocol)
   {
#ifdef BSD_SOCKETS
   case IPPROTO_TCP:
      if (type == SOCK_STREAM)
         break;
      /* IPPROTO_TCP protocol on non-SOCK_STREAM type socket */
      dtrap();
      return NULL;
   case IPPROTO_UDP:
      if (type == SOCK_DGRAM)
         break;
      /* IPPROTO_UDP protocol on non-SOCK_DGRAM type socket */
      dtrap();
      return NULL;
#endif /* BSD_SOCKETS */
   case 0:
      /* let protocol default based on socket type */
      break;
   default:
      /* unknown/unsupported protocol on socket */
      dtrap();
      return NULL;
   }
   return(pffindtype(domain, type));   /* map to findtype */
}
Пример #2
0
/* FUNCTION: tk_res_lock()
 *
 * Lock a NicheStack resource
 *
 * PARAM1: int                resource ID
 * PARAM2: int32_t            timout period or INFINITE_DELAY
 *
 * RETURN: none
 */
int
tk_res_lock(int resid, int32_t timeout)
{
   int err;
     
   if ((MIN_RESID <= resid) && (resid <= MAX_RESID))
   {
#ifdef DEBUG_TASK_STATE
      if (resid == FREEQ_RESID)
      {
         dprintf("LOCK(FREEQ): task = %s\n", tk_cur->tk_name);
      }
#endif

      /* wait for the semaphore */
      err = tk_mutex_pend(tk_resource[resid - MIN_RESID], timeout);
      if ((err != 0) && (timeout == INFINITE_DELAY))
      {
         dprintf("tk_res_lock error: %d\n", err);
         dtrap();
      }
   }
   else
   {
      err = -1;
      dtrap();                /* unknown resource ID */
   }

   return (err);
}
Пример #3
0
int
ln_uinit(LINEP line)
{
   int   unit;
   int   err;

   if (line->ln_state != LN_INITIAL)
   {
      dtrap();       /* don't call this multiple times */
      return (0);      /* return OK anyway... */
   }

   if (units_set++ > 0)
   {
      dtrap();    /* trying to set up multiple UARTs unsupported */
   }
   unit = 1;  /* channel 1 == unit 1 */
   err = uart_init(unit);  /* open UART and assign comport */
   
   if (err)
      return (err);    /* report hardware failures */

   line->lower_unit = unit;
   line->ln_state = LN_CONNECTED;
   uarts[unit].line = line;

   return (0);
}
Пример #4
0
int
del_route(ip_addr dest, ip_addr mask, int iface)
{
   struct net * ifp;
   ip_addr key;

   if(!rt_mib)    /* no route yet? */
      return 0;

   /* set the route interface pointer according to the index passed. This allows 
    * the passed index to be used to access dynamic interfaces, which do not appear 
    * in the nets[] array.
    */
   if(iface == -1)
      ifp = NULL;    /* wildcard */
   else
      ifp = if_getbynum(iface);

   /* If an iface was specified and a mask was given then just delete
    * the passed IP address entry and return.
    */
   if(mask == 0xFFFFFFFF)
   {
      struct avl_node * delnode;    /* node to delete */

       /* If the cached route is the one being deleted then clear the cache */
      if (cachedRoute->ipRouteDest == dest)
         cachedRoute = NULL;

      /* call btree route to remove the actual entry */
      delnode = avlv4_access((struct avl_node *)btreeRoot, (ntohl(dest)));
      if(!delnode)
      {
         dtrap();    /* node not in tree??? */
         return 0;   /* deleted 0 entries */
      }
	  ((RTMIB)delnode)->ipRouteNextHop = 0; /* clear route */
      key = htonl((((RTMIB)delnode)->ipRouteDest));
      avlremove((struct avl_node **)&btreeRoot, &key);
      return 1;      /* done, deleted one route entry */
   }

   /* fall to here if we are doing a wildcard delete. To do this we
    * traverse the whole tree, using a callback function to delete any
    * entry with the passed net. This is not really reentrant since
    * we use a static variable to count deletions, but the only ill
    * effect of reentering will be a bogus return count..
    */

   if(ifp == NULL)
   {
      dtrap();    /* illegal parameter combo */
      return ENP_PARAM;
   }

   rtdeletions = 0;     /* init number of routes deleted */
   avldepthfirst((struct avl_node *)btreeRoot, rtdel, (long)ifp, 0);
   return(rtdeletions);
}
Пример #5
0
void
wi_printf(wi_sess * sess, char * fmt, ...)
{
    int   len;
    va_list a;

    /* Since it's a huge pain to check the connection after each CGI write,
     * we may get sometimes handed a dying connection. Ignore these.
     */
    if(sess->ws_state == WI_ENDING)
        return;

    /* Try to make sure we won't overflow the print buffer */
    len = strlen(fmt);
    if(len > sizeof(output)/2 )
    {
        dtrap();
        dprintf("wi_printf: overflow, fmt: %s\n", fmt);
        return;
    }

    va_start(a, fmt);
    vsprintf(output, fmt, a);
    va_end(a);

    /* See if we overflowed the print buffer */
    len = strlen(output);
    if((output[DDB_SIZE-1] != 0) || len >= sizeof(output))
    {
        dprintf("wi_printf: overflow, output: %s\n", output);
        panic("wi_printf");
        return;
    }

    /* Print warnings if we even came close. */
    if(len > sizeof(output)/2 )
    {
        dtrap();
        dprintf("wi_printf warning: oversize line: %s", output);
    }

    /* see if new data will fit in existing buffer */
    if((sess->ws_txtail == NULL) ||
            (len >= (WI_TXBUFSIZE - sess->ws_txtail->tb_total)))
    {
        /* won't fit, get another buffer */
        if(wi_txalloc(sess) == NULL)
            return;
    }

    MEMCPY( &sess->ws_txtail->tb_data[sess->ws_txtail->tb_total],
            output, len);
    sess->ws_txtail->tb_total += len;
    return;
}
Пример #6
0
/* FUNCTION: v1_checksock()
 * 
 * v1_checksock() - Check if any SNMP requests have been
 * received on the socket. If yes, process them, and send the response.
 *
 * PARAM1: SOCKTYPE           socket
 *
 * RETURN: none
 */
void
v1_checksock(SOCKTYPE sock)
{
   struct sockaddr sa;
   int sa_len = sizeof(struct sockaddr);
   int e;
   int len = 0;

   /* check for received snmp packet */
   if (sock != INVALID_SOCKET)
   {
      len = recvfrom(sock, (char *)inbuf, SNMPSIZ, 0, &sa, &sa_len);
      if (len < 0)
      {
         e = t_errno(sock);
         if (e != EWOULDBLOCK) /* no data received */
         {
            dprintf("snmp: socket read error %d\n", e);
         }
         return;
      }
      else if (len == 0)
      {
         dtrap(); /* socket closed? */
         return;
      }
      /* else (len > 0) */

      if (agent_on)              /* agent is active */
      {
         LOCK_NET_RESOURCE(SNMP_RESID);
         e = snmp_agt_parse(inbuf, len, snmpbuf, SNMPSIZ);
         if (e)                  /* parse worked, send response packet */
         {
            len = e;    /* e is length of snmp reply */
            if (sa.sa_family == AF_INET)
               sa_len = sizeof(struct sockaddr_in);
#ifdef IP_V6
            else
               sa_len = sizeof(struct sockaddr_in6);
#endif
            e = sendto(sock, (char *)snmpbuf, len, 0, &sa, sa_len);
            if (e != len)
            {
               e = t_errno(sock);
               dprintf("snmp: socket send error \n");
               dtrap();
            }
         }
         UNLOCK_NET_RESOURCE(SNMP_RESID);
      }
   }
}
Пример #7
0
/* FUNCTION: tk_sem_post()
 *
 * Increment a semaphore count. If the count is greater than 0
 * and a task is waiting for the semaphore, decrement the semaphore
 * count, remove the task from the wait queue, and mark the task "ready".
 * If the semaphore ptr is NULL, use the task's semaphore.
 *
 * PARAM1: TASK *             task (NULL == current task)
 * PARAM2: IN_SEM *           semaphore (NULL == task's semaphore)
 * PARAM3: int                completion code to return to caller
 *
 * RETURN: int                SUCCESS or error code
 */
int
tk_sem_post(TASK *task, IN_SEM *sem)
{
   int  err = SUCCESS;

   ENTER_CRIT_SECTION();

   if (task == (TASK *)NULL)
      task = tk_cur;          /* default to current task */
   if (sem == (IN_SEM *)NULL)
      sem = task->tk_semaphore;

   TK_VALIDATE(task);

   if (!sem)
   {
      dtrap();                /* no semaphore! */
   }
   else
   {
#ifdef DEBUG_TASK
      if (sem->tk_tag != SEMA_TAG)
         dtrap();
#endif

      if (++sem->tk_count > sem->tk_maxcnt)
         sem->tk_count = sem->tk_maxcnt;

      /* set one or more (probably one) tasks "ready" */
#ifdef TCP_DEBUG
      if (sem->tk_count > 1)
         dprintf("tcp_wake: tk_count = %d\n", sem->tk_count);
#endif

      while ((sem->tk_count > 0) && ((task = sem->tk_waitq) != (TASK *)NULL))
      {
         if ((sem->tk_waitq = task->tk_waitq) != (TASK *)NULL)
            sem->tk_count--;
         else
            sem->tk_count = 0;

         task->tk_waitq = (TASK *)NULL;
         task->tk_event = NULL;
         TK_RESUME(task);
      }
   }

   EXIT_CRIT_SECTION();

   return (err);
}
Пример #8
0
int
tftp_upcall(PACKET pkt, void * data)
{
   struct tfconn * cn;
   struct udp * pup;

   /* get pointer to UDP header */
   pup = (struct udp *)pkt->nb_prot;
   pup -= 1;

   /* Find tftp session this packet is for. */
   if (data == TFTPSERVER)    /* tftp server connection */
   {
#ifdef TFTP_SERVER
      int err;
      /* call server for new session here */
      err = tfshnd(pkt->fhost, pup->ud_srcp, pkt->nb_prot);
#endif /* TFTP_SERVER */
      udp_free(pkt);
     /* do not return an error to the udp layer */
   }
   else  /* TFTP server child connection */
   {
      cn = (struct tfconn *)data;
      if (cn->tf_fhost != pkt->fhost)   /* sanity check */
      {
         dtrap();
         return ENP_NOT_MINE;
      }

      if (cn->tf_inbuf.udp_use)
      {
         dtrap(); /* ever happen? */
      }

      cn->tf_inbuf.data = pkt->nb_prot;
      cn->tf_inbuf.dlen = pkt->nb_plen;
      cn->tf_inbuf.udp_use = (void*)pkt;

      tftprcv(cn, pup->ud_srcp);    /* process the packet */

      if (cn->tf_inbuf.udp_use)     /* pkt may be freed in upcall */
      {
         udp_free(pkt);
         cn->tf_inbuf.udp_use = (PACKET)NULL;
      }
   }

   return 0;
}
Пример #9
0
void
tk_kill(task * tk_to_die)
{
   task *tk;

   if(tk_died)       /* Is another task in the process of dying? */
   {
      tk_yield();    /* this should allow it to finish */
      if(tk_died)    /* Other task still dying? */
      {
         dtrap();    /* system bug */
      }
   }
   /* hunt for the task which tk_to_die is the successor of */
   for (tk = tk_cur; tk->tk_next != tk_to_die; tk = tk->tk_next) ;

   /* now patch around tk_to_die */
   tk->tk_next = tk_to_die->tk_next;

   /* If I'm killing myself, die the next time I block */
   if (tk_cur == tk_to_die) 
   {
      tk_died = tk_cur;
   }
   else
      tk_del(tk_to_die);
}
Пример #10
0
/* FUNCTION: tk_mutex_free()
 *
 * Delete a mutex and wakeup any pending tasks.
 *
 * PARAM1: IN_MUTEX *         ptr to mutexaphore
 *
 * RETURN: none
 */
void
tk_mutex_free(IN_MUTEX *mutex)
{
   if (mutex)
   {
      TASK *tk = mutex->tk_waitq;

      ENTER_CRIT_SECTION();

#ifdef DEBUG_TASK
      if (mutex->tk_tag != MUTEX_TAG)
         dtrap();
#endif

      while (tk)
      {
         TASK *tk_next = tk->tk_waitq;

         tk->tk_waitq = (TASK *)NULL;
         tk->tk_event = NULL;
         TK_RESUME(tk);
         tk = tk_next;
      }

      npfree(mutex);

      EXIT_CRIT_SECTION();
   }
}
Пример #11
0
struct protosw *  
pffindtype(int domain, int type)
{

   /* check that the passed domain is vaid for the build */
   if (domain != AF_INET)
   {
#ifdef IP_V6
      if(domain != AF_INET6)
#endif
      {
         dtrap();    /* programming error */
         return NULL;
      }
   }

   if (type == SOCK_STREAM)
      return &tcp_protosw;
#ifdef UDP_SOCKETS
   else if(type == SOCK_DGRAM)
      return &udp_protosw;
#endif   /* UDP_SOCKETS */
#ifdef IP_RAW
   else if(type == SOCK_RAW)
      return &rawip_protosw;
#endif  /* IP_RAW */
   else
      return NULL;
}
Пример #12
0
/* FUNCTION: tk_sem_free()
 *
 * Delete a semaphore and wakeup any pending tasks.
 *
 * PARAM1: IN_SEM *           ptr to semaphore
 *
 * RETURN: none
 */
void
tk_sem_free(IN_SEM *sem)
{
   if (sem)
   {
      TASK *tk = sem->tk_waitq;

#ifdef DEBUG_TASK
      if (sem->tk_tag != SEMA_TAG)
         dtrap();
#endif
      ENTER_CRIT_SECTION();

      while (tk)
      {
         TASK *tk_next = tk->tk_waitq;

         TK_RESUME(tk);
         tk = tk_next;
      }

      npfree(sem);

      EXIT_CRIT_SECTION();
   }
}
Пример #13
0
void
LOCK_NET_RESOURCE(int resid)
{
   INT8U error = 0;
   int   errct = 0;

   if ((0 <= resid) && (resid <= MAX_RESID))
   {
      do
      {
         OSSemPend(resid_semaphore[resid], 0, &error);
         /* 
          * Sometimes we get a "timeout" error even though we passed a zero
          * to indicate we'll wait forever. When this happens, try again:
          */
         if ((error == 10) && (++errct > 1000))
         {
            panic("lock NET");   /* fatal */
            return;
         }
      } while (error == 10);
   }
   else
      dtrap();
}
Пример #14
0
int 
echo_svr_upcall(SOCKTYPE sock, PACKET inpkt, int err)
{
   int   e;

   if (sock != esvr_sock)
   {
      dtrap();
   }

   if (err)
   {
      if (inpkt)
         tcp_pktfree(inpkt);
      /* If this is a graceful close from the client then start our 
       * close too, else just print a message to console.
       */
      if (err == ESHUTDOWN)
      {
         /* tell tcp_echo_recv() to close the socket */
         esvr_sock_close = TRUE;
      }
      else
         dprintf("echo server callback error %d\n", err);
      e = 0;   /* should this be an error??? later */
   }
   else     /* return echo */
   {
      e = tcp_xout(sock, inpkt);
      if (e > 0)  /* ignore codes like ENP_SEND_PENDING */
         e = 0;
   }
   return e;
}
Пример #15
0
/* FUNCTION: wait_app_sem()
 *
 * Wait on an application semaphore
 *
 * PARAM1: unsigned long      semaphore ID
 *
 * RETURN: none
 *
 * This function is invoked by the PING and FTP client tasks to block while
 * they wait for the corresponding application event to be signaled.
 * The application event is signaled by the console task, or the 
 * Telnet server task, or the timer task upon the occurance of a relevant
 * event (e.g., configuration inputs from user, initiation of a new session,
 * or a periodic timeout notification.
 */
void
wait_app_sem(unsigned long semid)
{
   INT8U error = 0;
   int   errct = 0;

   if ((0 <= semid) && (semid <= MAX_SEMID))
   {
      do
      {
         OSSemPend(app_semaphore[semid], 0, &error);
         /* 
          * Sometimes we get a "timeout" error even though we passed a zero
          * to indicate we'll wait forever. When this happens, try again:
          */
         if ((error == 10) && (++errct > 1000))
         {
            panic("lock NET");   /* fatal */
            return;
         }
      } while (error == 10);
   }
   else
      dtrap();
}
Пример #16
0
/* FUNCTION: netdiag_dtrap()
 *
 * Invoke a dtrap() function. This will usually result in
 * control passing to a debugger.
 *
 * PARAM1: CLI_CTX            CLI context
 *
 * RETURN: int                0 or error code
 */
STATIC int
netdiag_dtrap(CLI_CTX ctx)
{
   if (!CLI_HELP(ctx))
      dtrap();

   return (0);
}
Пример #17
0
task * 
tk_new(task * prev_tk,     /* predecessor (sp?) to the new task */
   int    (*start)(int),   /* Where the new task starts execution. */
   int      stksiz,  /* The size in bytes of the stack of the new task. */
   char   * name,    /* The task's name as a string */
   int      arg)     /* argument to the task */
{
   task * tk;     /* a pointer to the new task */
   stack_t * sp;  /* pointer to task stack area for fill */

   /* create the new task */
   tk = (task *)TK_ALLOC(sizeof(task));
   if (tk == NULL)
   {
      ++tk_allocfail;
      return NULL;        /* if no memory left, return null */
   }
   tk->tk_size = stksiz;
   tk->tk_stack = (stack_t *)STK_ALLOC(stksiz);
   if (tk->tk_stack == NULL)
   {
      ++tk_allocfail;
      TK_FREE(tk);
      return NULL;
   }

   /* set it up to run */
   tk->tk_fp = tk_frame (tk, start, arg);

   /* fill stack with guardword */
   sp = tk->tk_fp;

#ifdef STK_TOPDOWN   /* Intel x86 "top down" stack */
   sp--;
   while (sp > tk->tk_stack)
   {
      sp--;
      *sp = GUARDWORD;
   }
#else /* stack moves from bottom up */
   dtrap(); /* untested */
   x = stksiz - (sp - tk->tk_stack);   /* bytes to fill */
   x = x/(sizeof(stack_t));
   x++;
   sp++;
   while (x++ > 0)
      *sp++ = GUARDWORD;   
#endif

   tk->tk_guard = sp;
   tk->tk_flags |= TF_AWAKE;  /* Schedule the task to run. */
   tk->tk_next = prev_tk->tk_next;  /* Fit it in after prev_tk. */
   prev_tk->tk_next = tk;
   tk->tk_name = name;        /* Set its name */
   tk->tk_count = 0;          /* init the count */

   return (tk);
}
Пример #18
0
struct mbuf *  
m_getnbuf(int type, int len)
{
   struct mbuf *  m;
   PACKET pkt = NULL;

#ifdef NPDEBUG
   if (type < MT_RXDATA || type > MT_IFADDR)
   {
      dtrap(); /* is this OK? */
   }
#endif

   /* if caller has data (len >= 0), we need to allocate 
    * a packet buffer; else all we need is the mbuf */
   if (len != 0)
   {
      LOCK_NET_RESOURCE(FREEQ_RESID);
      pkt = pk_alloc(len + HDRSLEN);

      UNLOCK_NET_RESOURCE(FREEQ_RESID);
      if (!pkt)
         return NULL;
   }

   m = (struct mbuf *)getq(&mfreeq);
   if (!m)
   {
      if (pkt) 
      {
         LOCK_NET_RESOURCE(FREEQ_RESID);
         pk_free(pkt);
         UNLOCK_NET_RESOURCE(FREEQ_RESID);
      }
      return NULL;
   }
   m->m_type = type;
   if (len == 0)
   {
      m->pkt = NULL;
      m->m_base = NULL;    /* caller better fill these in! */
      m->m_memsz = 0;
   }
   else
   {
      m->pkt = pkt;
      /* set m_data to the part where tcp data should go */
      m->m_base = m->m_data = pkt->nb_prot = pkt->nb_buff + HDRSLEN;
      m->m_memsz = pkt->nb_blen - HDRSLEN;
   }
   m->m_len = 0;
   m->m_next = m->m_act = NULL;
   mbstat.allocs++;        /* maintain local statistics */
   putq(&mbufq, (qp)m);
   return m;
}
Пример #19
0
/* FUNCTION: call_script_ctx()
 *
 * Execute commands from a script file.
 *   - A new GIO struct is pushed onto the GIO stack.
 *   - The input stream is set to the script file
 *   - The output stream is "null" of echo_out is FALSE.
 *   - Commands are parsed and executed until EOF is reached.
 *
 * PARAM1: CLI_CTX            current CLI context
 * PARAM2: void *             script name or memory address
 * PARAM3: int                input type: file or memory
 * PARAM4: bool_t             TRUE = echo commands to output stream
 * PARAM5: bool_t             FALSE = suppress command output
 * PARAM6: bool_t             TRUE = abort script on first error
 *
 * RETURN: int                0 or error code
 */
int
call_script_ctx(CLI_CTX ctx, void *cmdset, int type,
                bool_t echo_in, bool_t echo_out, bool_t halt)
{
   GIO   *gio = ctx->gio;
   VFILE *fd; 
   int   rtn;

   switch (type)
   {
   case CMDSFROMFILE:
      if ((fd = vfopen((char *)cmdset, "r")) == (VFILE *)NULL)
      {
/*       gio_printf(gio, "file not found: %s\n", cmdset); */
         return (ENP_NOFILE);
      }
      else
      {
         /* input = file */
         if ((rtn = GIO_PUSH_FILE(&ctx->gio, fd, GIO_RD)) != GIO_DONE)
         {
            vfclose(fd);
            return (rtn);
         }
         gio = ctx->gio;      /* update gio descriptor */

         /* if echo_out == FALSE, redirect output to "null" */
         if (!echo_out)
         {
            GIO_NULL(gio, GIO_WR);
         }

         /* set the GIO_F_ECHO flag if we are echoing commands */
         if (echo_in)
            gio->flags |= GIO_F_ECHO;
         else
            gio->flags &= ~GIO_F_ECHO;

         rtn = do_script(ctx, halt);

         vfclose(fd);         /* close the file */
         gio_pop(&ctx->gio);  /* destroy the script context */
      }   
      break;  
   
   case CMDSFROMMEM:
      /* not yet implemented */

   default:
      dtrap();                /* unknown script type */
      rtn = CLI_ERR_FATAL;
      break;
   }

   return (rtn);
}
Пример #20
0
void
DOMAIN_CHECK(struct socket * so, int size)
{
#ifdef IP_V4
   if((so->so_domain == AF_INET) &&
      (size < sizeof(struct sockaddr_in)))
   {
      dtrap(); /* programmer passed wrong structure */
   }
#endif   /* IP_V4 */

#ifdef IP_V6
   if((so->so_domain == AF_INET6) &&
      (size != sizeof(struct sockaddr_in6)))
   {
      dtrap(); /* programmer passed wrong structure */
   }
#endif   /* IP_V6 */
}
Пример #21
0
int
tftp_udpsend(struct tfconn *conn, void *outbuf, int outlen)
{
   PACKET pkt;
   int e;   /* error holder */

   pkt = (PACKET)conn->tf_outbuf.udp_use;

   /* sanity check buffer pointer */
   if ((char *)outbuf != pkt->nb_prot)
   {
      /* this is OK on retrys, but not initial sends */
      if (((char *)outbuf <= pkt->nb_buff) ||  /* null outbuf == bad */
         (conn->tf_tmo == 0)) /* this is not a retry */
      {
         dtrap();
         return ENP_LOGIC;
      }
   }

   pkt->nb_prot = (char*)outbuf;
   pkt->nb_plen = outlen;
   pkt->fhost = conn->tf_fhost;
   pkt->net = NULL;  /* force it to route */

#ifdef ZEROCOPY_API  /* packet can be marked in use, not freed */
   pkt->inuse = 2;   /* clone it so it won't pk_free() on send */
#else    /* need to copy data in case we have to retry */
   {
      PACKET pkt2;   /* packet to send & free */

      pkt2 = udp_alloc(outlen, 0);
      if (!pkt2)
         return ENP_NOBUFFER;

      pkt2->nb_plen = pkt->nb_plen;
      pkt2->fhost = pkt->fhost;
      pkt2->net = NULL;
      MEMCPY(pkt2->nb_prot, pkt->nb_prot, outlen);
      pkt = pkt2; /* send duplicate pkt, keep original in tf_conn */
   }
#endif

   e = udp_send(conn->tf_fport, conn->tf_lport, pkt);

   if (e < 0)
   {
#ifdef NPDEBUG
      dprintf("tftp_udpsend(): udp_send() error %d\n", e);
#endif
      return e;
   }
   else
      return 0;
}
Пример #22
0
void alt_iniche_init(void)
{
   extern OS_EVENT * mheap_sem_ptr;
   extern void *net_task_sem_ptr;

   /* initialize the npalloc() heap semaphore */
   mheap_sem_ptr = OSSemCreate(1);
   if (!mheap_sem_ptr)
      panic("mheap_sem_ptr create err"); 

   /* get the uCOS semaphore used for LOCK_NET_RESOURCE(NET_RESID) */
   net_task_sem_ptr = (void*)OSSemCreate(1);
   if (!net_task_sem_ptr)
      panic("net_task_sem_ptr create err"); 

   rcvdq_sem_ptr = OSSemCreate(0);
   if (!rcvdq_sem_ptr)
      panic("rcvdq_sem_ptr create err"); 

#ifdef OS_PREEMPTIVE
   ping_sem_ptr = OSSemCreate(0);       /* PING app */
   if (!ping_sem_ptr)
      panic("ping_sem_ptr create err");  
      
   ftpc_sem_ptr = OSSemCreate(0);       /* FTP Client app */
   if (!ftpc_sem_ptr)
      panic("ftpc_sem_ptr create err");  
#endif  /* OS_PREEMPTIVE */

#ifndef TCPWAKE_RTOS
   /* 
    * clear global_TCPwakeup_set
    */
   {
      int i;

      for (i = 0; i < GLOBWAKE_SZ; i++)
      {
         global_TCPwakeup_set[i].ctick = 0;
      }
      global_TCPwakeup_setIndx = 0;
   }

   {
      INT8U mute_err;

      global_wakeup_Mutex = OSMutexCreate(WAKEUP_MUTEX_PRIO, &mute_err);
      if (mute_err != OS_NO_ERR)
      {
         dprintf("*** uCOS init, can't create global_wakeup_Mutex = %d\n", mute_err);
         dtrap();
      }
   }
#endif  /* TCPWAKE_RTOS */
}
Пример #23
0
int 
tcp_client_del(TCPCLIENT tcpclient)
{
   int   e;
   TCPCLIENT tmpclient, prevclient;

   /* Close the underlying socket */
   if (tcpclient->sock != INVALID_SOCKET)
   {  
      e = socketclose(tcpclient->sock);
      if (e)
      {
         e = t_errno(tcpclient->sock);
         ns_printf(tcpclient->pio,"tcp echo: close error %d\n", e);
      }
   }

   /* Remove from the q */
   if (tcpq == tcpclient)
   {
      /* It is the first node */
      tcpq = tcpq->next;
   }
   else
   {
      prevclient=tcpq;
      tmpclient=tcpq->next;
      while (tmpclient)
      {
         if (tmpclient == tcpclient)
         {
            /* Found the node in the list */
            prevclient->next=tmpclient->next ;
            break;
         }
         else
         {
            prevclient=tmpclient;
            tmpclient=tmpclient->next ;
         }
      }

      /* Was the node found in Q ? */
      if (tmpclient == NULL)
      {
         /* Node not found in Q !! */
         dtrap();
         return TCPE_NODE_NOT_FOUND ;
      }
   }

   npfree(tcpclient);

   return SUCCESS;
}
Пример #24
0
/*
 * insertWakeSetEntry(void * event) - insert event into wake set,
 *  purge old entries.
 */
static void
insertWakeSetEntry(void * event)
{
   int i;
   struct TCP_PendPost *wakeP = &global_TCPwakeup_set[0];

   /* are we there already? */
   for (i = 0; i < global_TCPwakeup_setIndx; i++)
   {
      /* match? */
      if ((wakeP->ctick != 0) && (wakeP->soc_event == event))
      {
         /*
          * yup, return
          */
	 wakeP->ctick = cticks;		/* update cticks */
         return;				
      }
      wakeP++;
   }

   /* yup, use empty slot or purge an old one */
   wakeP = &global_TCPwakeup_set[0];
   for (i = 0; i < global_TCPwakeup_setIndx; i++)
   {
      /* empty or old? */
      if (!wakeP->ctick || 
          ((cticks - wakeP->ctick) > GLOBWAKE_PURGE_DELT))
      {
         /*
          * yup,  add ours
          */
         break;
      }
      wakeP++;
   }						

   if (i < GLOBWAKE_SZ)
   {
#ifdef TK_CRON_DIAGS
         dprintf("+++ insertWakeSetEntry add = %lx\n", event);
#endif	

         wakeP->ctick = cticks;				
         wakeP->soc_event = event;	
         if (i > global_TCPwakeup_setIndx)
            global_TCPwakeup_setIndx = i;
   }
   else
   {
      dprintf("*** insertWakeSetEntry, global_TCPwakeup_set is full - dtrap\n");
      dtrap();
   }
}
Пример #25
0
NET
if_getbynum(int ifnum)
{
   NET ifp;
   for (ifp = (NET)(netlist.q_head); ifp; ifp = ifp->n_next)
   {
      if(ifnum-- == 0)
         return ifp;
   }
   dtrap();
   return NULL;   /* list is not long enough */
}
Пример #26
0
/* FUNCTION: tk_mutex_post
 *
 * Free a currently held mutex.
 *
 * PARAM1: IN_MUTEX *         mutex
 *
 * RETURN: int                SUCCESS or error code
 */
int
tk_mutex_post(IN_MUTEX *mutex)
{
   int  err = SUCCESS;

   ENTER_CRIT_SECTION();

#ifdef DEBUG_TASK
   if (mutex && (mutex->tk_tag != MUTEX_TAG))
      dtrap();
#endif

   if ((mutex) && (mutex->tk_owner == tk_cur))
   {
      if (--mutex->tk_nesting <= 0)    /* done with mutex */
      {
         TASK *task = mutex->tk_waitq; /* next waiting task */

         /* is another task waiting for the mutex? */
         if ((mutex->tk_owner = task) != (TASK *)NULL)
         {
            mutex->tk_waitq = task->tk_waitq;
            mutex->tk_nesting = 1;
            task->tk_waitq = (TASK *)NULL;
            task->tk_event = NULL;
            TK_RESUME(task);
         }
      }

      EXIT_CRIT_SECTION();
   }
#ifdef DEBUG_TASK
   else
      dtrap();
#endif

   return (err);
}
Пример #27
0
void TK_OSTaskResume(u_char * Id)
{
INT8U err;

   err = OSTaskResume(*Id);
   
   if ((err != OS_NO_ERR) && (err != OS_TASK_NOT_SUSPENDED))
   {
      dprintf("ChronOS API call failure, to Resume Suspended Task!\n");
      dtrap();
      panic("TK_OSTaskResume");      
   }
   return;
}
Пример #28
0
int
em_fwrite(char * buf, unsigned size1, unsigned size2, void * fd)
{
   int      error;

   dtrap();

   USE_ARG(buf);
   USE_ARG(size1);
   USE_ARG(size2);
   error = em_verify((EOFILE*)fd);
   if(error)
      return error;
   return 0;
}
Пример #29
0
void
UNLOCK_NET_RESOURCE(int resid)
{
   INT8U error = 0;

   if ((0 <= resid) && (resid <= MAX_RESID))
   {
      error = OSSemPost(resid_semaphore[resid]);
      if (error != OS_NO_ERR)
      {
         panic("unlock NET");
      }
   }
   else
      dtrap();
}
Пример #30
0
void
post_app_sem(unsigned long semid)
{
   INT8U error;

   if ((0 <= semid) && (semid <= MAX_SEMID))
   {
      error = OSSemPost(app_semaphore[semid]);
      if (error != OS_NO_ERR)
      {
         panic("unlock NET");
      }
   }
   else
      dtrap();
}