Beispiel #1
0
static void *read_thread(void *data)
{
	struct vidsrc_st *st = data;

	while (st->run) {
		AVPacket pkt;

		av_init_packet(&pkt);

		if (av_read_frame(st->ic, &pkt) < 0) {
			sys_msleep(1000);
			av_seek_frame(st->ic, -1, 0, 0);
			continue;
		}

		if (pkt.stream_index != st->sindex)
			goto out;

		handle_packet(st, &pkt);

		/* simulate framerate */
		sys_msleep(1000/st->fps);

	out:
#if LIBAVCODEC_VERSION_INT >= ((57<<16)+(12<<8)+100)
		av_packet_unref(&pkt);
#else
		av_free_packet(&pkt);
#endif
	}

	return NULL;
}
Beispiel #2
0
static void *read_thread(void *data)
{
	struct vidsrc_st *st = data;

	while (st->run) {
		AVPacket pkt;

		av_init_packet(&pkt);

		if (av_read_frame(st->ic, &pkt) < 0) {
			sys_msleep(1000);
			av_seek_frame(st->ic, -1, 0, 0);
			continue;
		}

		if (pkt.stream_index != st->sindex)
			goto out;

		handle_packet(st, &pkt);

		/* simulate framerate */
		sys_msleep(1000/st->fps);

	out:
		av_free_packet(&pkt);
	}

	return NULL;
}
Beispiel #3
0
static void *tx_thread(void *arg)
{
	struct audio *a = arg;
	struct autx *tx = &a->tx;
	unsigned i;

	/* Enable Real-time mode for this thread, if available */
	if (a->cfg.txmode == AUDIO_MODE_THREAD_REALTIME)
		(void)realtime_enable(true, 1);

	while (a->tx.u.thr.run) {

		for (i=0; i<16; i++) {

			if (aubuf_cur_size(tx->aubuf) < tx->psize)
				break;

			poll_aubuf_tx(a);
		}

		sys_msleep(5);
	}

	return NULL;
}
Beispiel #4
0
static void *play_thread(void *arg)
{
	uint64_t now, ts = tmr_jiffies();
	struct ausrc_st *st = arg;
	int16_t *sampv;

	sampv = mem_alloc(st->sampc * 2, NULL);
	if (!sampv)
		return NULL;

	while (st->run) {

		sys_msleep(4);

		now = tmr_jiffies();

		if (ts > now)
			continue;

		aubuf_read_samp(st->aubuf, sampv, st->sampc);

		st->rh(sampv, st->sampc, st->arg);

		ts += st->ptime;
	}

	mem_deref(sampv);

	info("aufile: player thread exited\n");

	return NULL;
}
Beispiel #5
0
static void *read_thread(void *arg)
{
	struct vidsrc_st *st = arg;
	uint64_t ts = 0;

	while (st->run) {

		uint64_t now;

		sys_msleep(2);

		now = tmr_jiffies();
		if (!ts)
			ts = now;

		if (ts > now)
			continue;

		process(st);

		ts += 1000/st->prm.fps;
	}

	return NULL;
}
Beispiel #6
0
void
sys_threadpool_destroy(sys_threadpool *pool)
{
	size_t i;

	if (!pool)
		return;
	
	pool->shutdown = true;

	sys_threadpool_wait_all(pool, UINT32_MAX);

	sys_msleep(10);

	sys_tls_free_key(pool->worker_key);

	for (i = 0; i < pool->workers.count; ++i)
		sys_thread_destroy(((sys_worker *)rt_array_get(&pool->workers, i))->thread);

	rt_array_release(&pool->workers);
	rt_array_release(&pool->active_tasks);

	rt_queue_release(&pool->task_queue);

	sys_cond_var_destroy(pool->task_notify);
	sys_mutex_destroy(pool->task_mutex);

	free(pool);
}
Beispiel #7
0
static void
ping_thread(void *arg)
{
  int s;
  int timeout = PING_RCV_TIMEO;
  ip_addr_t ping_target;

  LWIP_UNUSED_ARG(arg);

  if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
    return;
  }

  lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));

  while (1) {
    ping_target = PING_TARGET;

    if (ping_send(s, &ping_target) == ERR_OK) {
      LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
      ip_addr_debug_print(PING_DEBUG, &ping_target);
      LWIP_DEBUGF( PING_DEBUG, ("\n"));

      ping_time = sys_now();
      ping_recv(s);
    } else {
      LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
      ip_addr_debug_print(PING_DEBUG, &ping_target);
      LWIP_DEBUGF( PING_DEBUG, (" - error\n"));
    }
    sys_msleep(PING_DELAY);
  }
}
Beispiel #8
0
/**
 * SNTP thread
 */
static void
sntp_thread(void *arg)
{
  LWIP_UNUSED_ARG(arg);
  while(1) {
    sntp_request();
    sys_msleep(SNTP_UPDATE_DELAY);
  }
}
Beispiel #9
0
static void ausrc_destructor(void *arg)
{
	struct ausrc_st *st = arg;
	struct session *sess = st->sess;
	warning("DESTRUCT ausrc\n");
	sess->run_src = false;
	sys_msleep(20);
	mem_deref(st->sampv);
}
Beispiel #10
0
/**
 * SNTP thread
 */
static void sntp_thread(void *arg) {
	LWIP_UNUSED_ARG(arg);
	while (1) {
		dns_gethostbyname(SNTP_SERVER_NAME, &SNTPaddr, sntp_server_found, NULL);
		vTaskSuspend(NULL);
		sntp_request();
		sys_msleep(SNTP_UPDATE_DELAY);
	}
}
Beispiel #11
0
static void *read_thread(void *data)
{
	struct vidsrc_st *st = data;

	uint64_t now, ts = tmr_jiffies();

	while (st->run) {
		AVPacket pkt;
		int ret;

		sys_msleep(4);
		now = tmr_jiffies();

		if (ts > now)
			continue;

		av_init_packet(&pkt);

		ret = av_read_frame(st->ic, &pkt);
		if (ret < 0) {
			debug("avformat: rewind stream (ret=%d)\n", ret);
			sys_msleep(1000);
			av_seek_frame(st->ic, -1, 0, 0);
			continue;
		}

		if (pkt.stream_index != st->sindex)
			goto out;

		handle_packet(st, &pkt);

		ts += (uint64_t) 1000 * pkt.duration * av_q2d(st->time_base);

	out:
#if LIBAVCODEC_VERSION_INT >= ((57<<16)+(12<<8)+100)
		av_packet_unref(&pkt);
#else
		av_free_packet(&pkt);
#endif
	}

	return NULL;
}
Beispiel #12
0
static void auplay_destructor(void *arg)
{
	struct auplay_st *st = arg;
	struct session *sess = st->sess;
	warning("DESTRUCT auplay\n");
	sess->run_play = false;
	sys_msleep(20);
	mem_deref(st->sampv);
	mem_deref(sess->dstmix);
}
Beispiel #13
0
int HLR2::_exec(const char *url, const char *payload, unsigned short timeout, pugi::xml_document& doc, std::string& headers)
{
    const short maxTry = 3;
    short retry = 0;

    if (!url || !*url) {
        LOG_ERROR("%s::%s: Invalid URL!", __class__, __func__);
        return -1;
    }

    while (maxTry >= ++retry) {
        short status = _hc.httpPost(url, payload, "text/xml", timeout);
        LOG_INFO("%s::%s: url: %s, payload: %s, timeout: %d, status: %d, headers: %s, body: %s", __class__, __func__,
                url, payload, timeout, status, _hc.getResponseHeaders(), _hc.getResponseBody());

        if (200 != status && 307 != status) {
            return -1;
        }

        headers = _hc.getResponseHeaders();
        std::string body = _hc.getResponseBody();

        if (!doc.load(body.c_str())) {
            LOG_ERROR("%s::%s: Malformed XML response!: %s", __class__, __func__, body.c_str());
            return -1;
        }

        pugi::xml_node result = doc.find_node(_isResult);
        int resultCode = atoi(result.child("ResultCode").child_value());

        switch (resultCode) {
            case 0:
            case 3016:
            case 3810:
                //-- success, exit...
                return 0;
            case 5004:
                //-- invalid session, retry...
                LOG_INFO("%s::%s: Will retry: %d", __class__, __func__, retry);
                break;
            default:
                LOG_ERROR("%s::%s: ResultCode: %s, ResultDesc: %s", __class__, __func__,
                        result.child("ResultCode").child_value(), result.child("ResultDesc").child_value());
                return -1;
        }

        //-- wait for a while...
        sys_msleep(1000);
    }

    return -1;
}
static void
timeout_thread(void *arg)
{
  int i;
  
  for (i = 0; i < TIMERS; i++) {
	  diag_printf("Adding timer #%d\n", i);
	  timers[i] = timeout_fn;
	  intervals[i] = (i+1)*1000;	
	  sys_timeout(intervals[i],  timers[i], (void *)i);
  }
  sys_msleep(0); 
  diag_printf("Done\n");
}
Beispiel #15
0
/* Close a PPP connection and release the descriptor. 
 * Any outstanding packets in the queues are dropped.
 * Return 0 on success, an error code on failure. */
int pppClose(int pd)
{
    PPPControl *pc = &pppControl[pd];
    int st = 0;

    /* Disconnect */
    pc->kill_link = !0;
    pppMainWakeup(pd);
    
    if(!pc->linkStatusCB) {
	    while(st >= 0 && lcp_phase[pd] != PHASE_DEAD) {
		    sys_msleep(500);
		    break;
	    }
    }
    return st;
}
Beispiel #16
0
static void *tx_thread(void *arg)
{
	struct audio *a = arg;

	/* Enable Real-time mode for this thread, if available */
	if (a->cfg.txmode == AUDIO_MODE_THREAD_REALTIME)
		(void)realtime_enable(true, 1);

	while (a->tx.u.thr.run) {

		poll_aubuf_tx(a);

		sys_msleep(5);
	}

	return NULL;
}
Beispiel #17
0
/**
 * RTP send thread
 */
static void
rtp_send_thread(void *arg)
{
  int                sock;
  struct sockaddr_in local;
  struct sockaddr_in to;
  u32_t              rtp_stream_address;

  LWIP_UNUSED_ARG(arg);

  /* initialize RTP stream address */
  rtp_stream_address = RTP_STREAM_ADDRESS;

  /* if we got a valid RTP stream address... */
  if (rtp_stream_address != 0) {
    /* create new socket */
    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock >= 0) {
      /* prepare local address */
      memset(&local, 0, sizeof(local));
      local.sin_family      = AF_INET;
      local.sin_port        = PP_HTONS(INADDR_ANY);
      local.sin_addr.s_addr = PP_HTONL(INADDR_ANY);

      /* bind to local address */
      if (bind(sock, (struct sockaddr *)&local, sizeof(local)) == 0) {
        /* prepare RTP stream address */
        memset(&to, 0, sizeof(to));
        to.sin_family      = AF_INET;
        to.sin_port        = PP_HTONS(RTP_STREAM_PORT);
        to.sin_addr.s_addr = rtp_stream_address;

        /* send RTP packets */
        memset(rtp_send_packet, 0, sizeof(rtp_send_packet));
        while (1) {
          rtp_send_packets( sock, &to);
          sys_msleep(RTP_SEND_DELAY);
        }
      }

      /* close the socket */
      closesocket(sock);
    }
  }
}
Beispiel #18
0
void* default_unli_parser (void* arg)
{
    void* retr = NULL;
    std::vector<std::string> list;
    std::string pattern = std::string(Config::getLocalProcessedDir()) + std::string("*.csv");
    std::vector<default_unli_t> default_unlis;

    LOG_INFO("%s: Started.", __func__);
    LOG_INFO("%s: processing %s files.", __func__, pattern.c_str());

    while (! IS_SHUTDOWN()) {
        glob(list,  pattern);
        //LOG_DEBUG("%s: got %d files.", __func__, list.size());

        for (size_t i=0; i<list.size(); ++i) {
            std::string &src = list[i];
            std::string dest = Config::getLocalCompletedDir() + basename(src);

            load_default_unli(default_unlis, src);
            LOG_INFO("%s: got %d items from %s.", __func__, default_unlis.size(), src.c_str());

            if (0 != mv(src, dest)) {
                LOG_ERROR("%s: Unable to move '%s' to '%s'", __func__, src.c_str(), dest.c_str());
                continue;
            }

            for (size_t j=0; j<default_unlis.size(); ++j) {
                default_unli_t& default_unli = default_unlis[j];
                if (0 != c2q_enqueue(Global::getDefaultUnliQ(), (void*) &default_unli, sizeof(default_unli_t))) {
                    LOG_ERROR("%s: Unable to insert to default_unli queue: msisdn: %s, mnc: %s, mcc: %s, sgsn_ip: %s, date: %s, filename: %s", __func__
                            , default_unli.msisdn, default_unli.mnc, default_unli.mcc
                            , default_unli.sgsn_ip, default_unli.date, default_unli.filename);
                }
            }
        }
        
        //-- sleep for a while
        sys_msleep(1000);
    }


    LOG_INFO("%s: Terminated.", __func__);

    return retr;
}
int MQTTYield(MQTTClient* c, int timeout_ms)
{
	int rc = SUCCESS;
	Timer timer;
	TimerInit(&timer);

#if defined(MQTT_TASK)
	FreeRTOS_MutexLock(&c->mutex);
#endif
	TimerCountdownMS(&timer, timeout_ms);
	//printf(".");
	rc = cycle(c, &timer);
#if defined(MQTT_TASK)
	FreeRTOS_MutexUnlock(&c->mutex);
#endif
	sys_msleep(1); 

	return rc;
}
Beispiel #20
0
static void *read_thread(void *arg)
{
	struct vidsrc_st *st = arg;
	uint64_t ts = tmr_jiffies();

	while (st->run) {

		if (tmr_jiffies() < ts) {
			sys_msleep(4);
			continue;
		}

		st->frameh(st->frame, st->arg);

		ts += (1000/st->fps);
	}

	return NULL;
}
static void
ping_host_thread(void *arg)
{
  int s,i=0;
  int timeout = PING_RCV_TIMEO;
  ip_addr_t ping_target;
  char *host = (char *)arg;
  //LWIP_UNUSED_ARG(arg);

  if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
    return;
  }

  lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));

  while (1) {
    //ping_target = PING_TARGET;
	if (i>4) break;
	i++;  
	(ip4_addr_set_u32(&ping_target, ipaddr_addr(host)));

    if (ping_send(s, &ping_target) == ERR_OK) {
      //LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
      //ip_addr_debug_print(PING_DEBUG, &ping_target);
      //LWIP_DEBUGF( PING_DEBUG, ("\n"));
			rt_kprintf("ping: send ");
			ip_addr_debug_print1(&ping_target);
			rt_kprintf("\n");
		
      ping_time = sys_now();
      ping_recv(s);
    } else {
      //LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
      //ip_addr_debug_print(PING_DEBUG, &ping_target);
      //LWIP_DEBUGF( PING_DEBUG, (" - error\n"));
			rt_kprintf("ping: send ");
			ip_addr_debug_print1(&ping_target);
			rt_kprintf(" - error\n");
    }
    sys_msleep(PING_DELAY);
  }
}
static void
ping_host(char * host)
{
	int s,i=0;
	int timeout = PING_RCV_TIMEO;
	ip_addr_t ping_target;


	if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
		return;
	}

	lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));

	while (1) {
		if (i>4) break;
		i++;  
		//ping_target = netif_default->gw;
		//IP4_ADDR(&ping_target,210,82,5,1);
		(ip4_addr_set_u32(&ping_target, ipaddr_addr(host))); 

		if (ping_send(s, &ping_target) == ERR_OK) {
			//LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
			rt_kprintf("ping: send ");
			ip_addr_debug_print1(&ping_target);
			rt_kprintf("\n");

			ping_time = sys_now();
			ping_recv(s);
		} else {
			//LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
			rt_kprintf("ping: send ");
			ip_addr_debug_print1(&ping_target);
			rt_kprintf(" - error\n");
			//LWIP_DEBUGF( PING_DEBUG, (" - error\n"));
		}
		sys_msleep(PING_DELAY);
	}
}
Beispiel #23
0
static void *play_thread(void *arg)
{
	uint64_t now, ts = tmr_jiffies();
	struct ausrc_st *st = arg;
	int16_t *sampv;

	sampv = mem_alloc(st->sampc * 2, NULL);
	if (!sampv)
		return NULL;

	while (st->run) {

		sys_msleep(4);

		now = tmr_jiffies();

		if (ts > now)
			continue;

#if 1
		if (now > ts + 100) {
			debug("aufile: cpu lagging behind (%llu ms)\n",
			      now - ts);
		}
#endif

		aubuf_read_samp(st->aubuf, sampv, st->sampc);

		st->rh(sampv, st->sampc, st->arg);

		ts += st->ptime;
	}

	mem_deref(sampv);

	info("aufile: player thread exited\n");

	return NULL;
}
Beispiel #24
0
static void *play_thread(void *arg)
{
	uint64_t now, ts = tmr_jiffies();
	struct ausrc_st *st = arg;
	void *sampv;
	size_t num_bytes = st->sampc * st->sampsz;

	sampv = mem_alloc(num_bytes, NULL);
	if (!sampv)
		return NULL;

	while (st->run) {

		sys_msleep(4);

		now = tmr_jiffies();

		if (ts > now)
			continue;
#if 1
		if (now > ts + 100) {
			debug("rst: cpu lagging behind (%u ms)\n",
			      now - ts);
		}
#endif

		aubuf_read(st->aubuf, sampv, num_bytes);

		st->rh(sampv, st->sampc, st->arg);

		ts += st->ptime;
	}

	mem_deref(sampv);

	return NULL;
}
Beispiel #25
0
Datei: sys.c Projekt: BFridge/OS
/**
 * This is the main system call function. It takes an interrupt stack frame
 * and decodes which interrupt number generated the system call. This number
 * is used to decode which system call was called.
 *
 * The stack frame is used to both pass and receive information from the
 * system call.
 * ECX: On completion of the system call ecx is populated with the return
 *      value
 * EAX: Contains the system call number
 * EBX: Contains the ptr to the first of the parameters
 *
 * @param frame Ptr to a handler_stack_frame struture
 * @return SUCCESS on success or FAILURE if something goes wrong
 */
int system_call( struct handler_stack_frame* frame )
{
    int system_call_number;
    char** system_call_params;
    int* system_call_result;

    system_call_result = (int*)frame->ecx;
    system_call_params = (char**)frame->ebx;
    system_call_number = frame->eax;

    switch( system_call_number )
    {
    case SYS_SEMA_CREATE:
        *system_call_result = semaphore_create( (sema_handle*)system_call_params[0], (int)system_call_params[1] );
        break;
    case SYS_SEMA_WAIT:
        *system_call_result = semaphore_wait( (int)system_call_params[0] );
        break;
    case SYS_SEMA_SIGNAL:
        *system_call_result = semaphore_signal( (int)system_call_params[0] );
        break;
    case SYS_SEMA_DESTROY:
        *system_call_result = semaphore_destroy( (int)system_call_params[0] );
        break;
    case SYS_THREAD_EXIT:
        *system_call_result = sys_thread_exit();
        break;
    case SYS_MSLEEP:
        *system_call_result = sys_msleep((uint)system_call_params[0] );
        break;
    default:
        *system_call_result = FAILURE;
        break;
    }

    return SUCCESS;
}
Beispiel #26
0
/* This is somewhat different to other ports: we have a main loop here:
 * a dedicated task that waits for packets to arrive. This would normally be
 * done from interrupt context with embedded hardware, but we don't get an
 * interrupt in windows for that :-) */
void main_loop()
{
#if !NO_SYS
  err_t err;
  sys_sem_t init_sem;
#endif /* NO_SYS */
#if PPP_SUPPORT
#if !USE_ETHERNET
  int count;
  u8_t rxbuf[1024];
#endif
  volatile int callClosePpp = 0;
#endif /* PPP_SUPPORT */

  /* initialize lwIP stack, network interfaces and applications */
#if NO_SYS
  lwip_init();
  test_init(NULL);
#else /* NO_SYS */
  err = sys_sem_new(&init_sem, 0);
  tcpip_init(test_init, &init_sem);
  /* we have to wait for initialization to finish before
   * calling update_adapter()! */
  sys_sem_wait(&init_sem);
  sys_sem_free(&init_sem);
#endif /* NO_SYS */

  /* MAIN LOOP for driver update (and timers if NO_SYS) */
  while (!_kbhit()) {
#if NO_SYS
    /* handle timers (already done in tcpip.c when NO_SYS=0) */
    sys_check_timeouts();
#endif /* NO_SYS */

#if USE_ETHERNET
#if !PCAPIF_RX_USE_THREAD
    /* check for packets and link status*/
    pcapif_poll(&netif);
    /* When pcapif_poll comes back, there are not packets, so sleep to
       prevent 100% CPU load. Don't do this in an embedded system since it
       increases latency! */
    sys_msleep(1);
#else /* !PCAPIF_RX_USE_THREAD */
    sys_msleep(50);
#endif /* !PCAPIF_RX_USE_THREAD */
#else /* USE_ETHERNET */
#if 0 /* set this to 1 if PPP_INPROC_OWNTHREAD==0 or not defined (see ppp.c) */
    /* try to read characters from serial line and pass them to PPPoS */
    count = sio_read(ppp_sio, (u8_t*)rxbuf, 1024);
    if(count > 0) {
      pppos_input(ppp_desc, rxbuf, count);
    } else
#endif
    {
      /* nothing received, give other tasks a chance to run */
      sys_msleep(1);
    }

#endif /* USE_ETHERNET */
#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
    /* check for loopback packets on all netifs */
    netif_poll_all();
#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
#if PPP_SUPPORT
    {
    int do_hup = 0;
    if(do_hup) {
      pppSigHUP(ppp_desc);
      do_hup = 0;
    }
    }
    if(callClosePpp && (ppp_desc >= 0)) {
      /* make sure to disconnect PPP before stopping the program... */
      callClosePpp = 0;
#if NO_SYS
      pppClose(ppp_desc);
#else
      tcpip_callback_with_block(pppCloseCallback, (void*)ppp_desc, 0);
#endif
      ppp_desc = -1;
    }
#endif /* PPP_SUPPORT */
  }

#if PPP_SUPPORT
    if(ppp_desc >= 0) {
      u32_t started;
      printf("Closing PPP connection...\n");
      /* make sure to disconnect PPP before stopping the program... */
#if NO_SYS
      pppClose(ppp_desc);
#else
      tcpip_callback_with_block(pppCloseCallback, (void*)ppp_desc, 0);
#endif
      ppp_desc = -1;
      /* Wait for some time to let PPP finish... */
      started = sys_now();
      do
      {
#if USE_ETHERNET && !PCAPIF_RX_USE_THREAD
        pcapif_poll(&netif);
#else /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */
        sys_msleep(50);
#endif /* USE_ETHERNET && !PCAPIF_RX_USE_THREAD */
        /* @todo: need a better check here: only wait until PPP is down */
      } while(sys_now() - started < 5000);
    }
#endif /* PPP_SUPPORT */
#if USE_ETHERNET
  /* release the pcap library... */
  pcapif_shutdown(&netif);
#endif /* USE_ETHERNET */
}
void uip_task(void *p)
{
	int i;
  	struct timer periodic_timer, arp_timer;

  	enc28j60_open();	

  	timer_set(&periodic_timer, CLOCK_SECOND / 2);
  	timer_set(&arp_timer, CLOCK_SECOND * 10);  
  	
  	
  	while(1) 
  	{
  		socket_process_pending_lists_();
  		
    	uip_len = enc28j60_read();
    	
    	if(uip_len > 0) 
    	{
      		if(BUF->type == htons(UIP_ETHTYPE_IP)) 
      		{
        		uip_input();
        		/* If the above function invocation resulted in data that
           		should be sent out on the network, the global variable
           		uip_len is set to a value > 0. */
        		if(uip_len > 0) 
        		{
          			uip_arp_out();
          			enc28j60_write();
        		}
      		} 
      		else if(BUF->type == htons(UIP_ETHTYPE_ARP)) 
      		{
        		uip_arp_arpin();
        		/* If the above function invocation resulted in data that
           		should be sent out on the network, the global variable
           		uip_len is set to a value > 0. */
        		if(uip_len > 0) 
        		{
          			enc28j60_write();
        		}
      		}

		} 
		
		if(timer_expired(&periodic_timer)) 
		{
      		timer_reset(&periodic_timer);
      		for(i = 0; i < UIP_CONNS; i++) 
      		{
        		uip_periodic(i);
        		/* If the above function invocation resulted in data that
           		should be sent out on the network, the global variable
           		uip_len is set to a value > 0. */
        		if(uip_len > 0) 
        		{
          			uip_arp_out();
          			enc28j60_write();
        		}
      		}

#if UIP_UDP
      		for(i = 0; i < UIP_UDP_CONNS; i++) 
      		{
        		uip_udp_periodic(i);
        		/* If the above function invocation resulted in data that
           		should be sent out on the network, the global variable
           		uip_len is set to a value > 0. */
        		if(uip_len > 0) 
        		{
          			uip_arp_out();
          			enc28j60_write();
        		}
        	}
#endif /* UIP_UDP */           
      		/* Call the ARP timer function every 10 seconds. */
      		if(timer_expired(&arp_timer)) 
      		{
      			timer_reset(&arp_timer);
      			uip_arp_timer();
      		}
    	}
    	
    	//yield so that other tasks can do something
    	sys_msleep(UIP_TASK_YIELD_TIME_MS);
	}
  	
}
Beispiel #28
0
void* default_unli_handler (void* arg)
{
    void* retr = NULL;
    long proc_id = (long)arg;

    if (OraDBDefaultUnli::init_lib() < 0) {
        LOG_CRITICAL("%s: %d: Unable to initialize libsqlora8!", __func__, proc_id);
        DO_ABORT();
        return retr;
    }

    OraDBDefaultUnli conn;
    if (conn.initialize(Config::getOraAuth()) < 0) {
        LOG_CRITICAL("%s: %d: Unable to connect to db (%s).", __func__, proc_id, Config::getOraAuth());
        DO_ABORT();
        return retr;
    }

    LOG_INFO("%s: %d: Started.", __func__, proc_id);

    while (! IS_SHUTDOWN()) {
        default_unli_t default_unli;

        while (! c2q_dequeue(Global::getDefaultUnliQ(), &default_unli, sizeof(default_unli_t))) {
            if (! strcmp(default_unli.mcc, "515")) {
                LOG_DEBUG("%s: %d: Ignoring records with mcc 515: msisdn: %s, mnc: %s, mcc: %s, sgsn_ip: %s, tac_tai: %s, date: %s, filename: %s", __func__, proc_id
                        , default_unli.msisdn, default_unli.mnc, default_unli.mcc, default_unli.sgsn_ip, default_unli.tac_tai, default_unli.date, default_unli.filename);
                continue;
            }

            //-- process default unli transaction...
            conn.processDefaultUnli(&default_unli);

            LOG_DEBUG("%s: %d: db_retr: %d, msisdn: %s, mnc: %s, mcc: %s, sgsn_ip: %s, tac_tai: %s, date: %s, filename: %s", __func__, proc_id
                    , default_unli.db_retr, default_unli.msisdn, default_unli.mnc, default_unli.mcc, default_unli.sgsn_ip, default_unli.tac_tai
                    , default_unli.date, default_unli.filename);

            switch (default_unli.db_retr) {
                case DB_RETR_NF_BUS:
                    //-- call NF Bus...
                    doNfBus(&default_unli);
                    //if (0 == doNfBus(&default_unli)) {
                        // send_system_msg("TRIGGER", TRAN_TYPE_BROADCAST, 0,
                        //        Config::getAccessCode(), default_unli.msisdn, SYSMSG_BROADCAST_ROAM_FREE_CT, 1);
                    //}
                    //-- continue...
                case DB_RETR_OK:
                    //-- call matrix api...
                    doMatrix(&default_unli);
                    break;
                default:
                    LOG_ERROR("%s: %d: Unable to process default_unli: retr: %d, msisdn: %s, mnc: %s, mcc: %s, sgsn_ip: %s, tac_tai: %s, date: %s, filename: %s", __func__, proc_id
                            , default_unli.db_retr, default_unli.msisdn, default_unli.mnc, default_unli.mcc, default_unli.sgsn_ip, default_unli.tac_tai
                            , default_unli.date, default_unli.filename);
            }
        }

        //-- sleep for a while
        sys_msleep(1000);
    }

    LOG_INFO("%s: %d: Terminated.", __func__, proc_id);

    conn.destroy_db();

    return retr;
}
/*
 * check_passwd - Check the user name and passwd against the PAP secrets
 * file.  If requested, also check against the system password database,
 * and login the user if OK.
 *
 * returns:
 *  UPAP_AUTHNAK: Authentication failed.
 *  UPAP_AUTHACK: Authentication succeeded.
 * In either case, msg points to an appropriate message.
 */
int
check_passwd( int unit, char *auser, int userlen, char *apasswd, int passwdlen, char **msg, int *msglen)
{
#if 1
  LWIP_UNUSED_ARG(unit);
  LWIP_UNUSED_ARG(auser);
  LWIP_UNUSED_ARG(userlen);
  LWIP_UNUSED_ARG(apasswd);
  LWIP_UNUSED_ARG(passwdlen);
  LWIP_UNUSED_ARG(msglen);
  *msg = (char *) 0;
  return UPAP_AUTHACK;     /* XXX Assume all entries OK. */
#else
  int ret = 0;
  struct wordlist *addrs = NULL;
  char passwd[256], user[256];
  char secret[MAXWORDLEN];
  static u_short attempts = 0;

  /*
   * Make copies of apasswd and auser, then null-terminate them.
   */
  BCOPY(apasswd, passwd, passwdlen);
  passwd[passwdlen] = '\0';
  BCOPY(auser, user, userlen);
  user[userlen] = '\0';
  *msg = (char *) 0;

  /* XXX Validate user name and password. */
  ret = UPAP_AUTHACK;     /* XXX Assume all entries OK. */

  if (ret == UPAP_AUTHNAK) {
    if (*msg == (char *) 0) {
      *msg = "Login incorrect";
    }
    *msglen = strlen(*msg);
    /*
     * Frustrate passwd stealer programs.
     * Allow 10 tries, but start backing off after 3 (stolen from login).
     * On 10'th, drop the connection.
     */
    if (attempts++ >= 10) {
      AUTHDEBUG((LOG_WARNING, "%d LOGIN FAILURES BY %s\n", attempts, user));
      /*ppp_panic("Excess Bad Logins");*/
    }
    if (attempts > 3) {
      sys_msleep((attempts - 3) * 5);
    }
    if (addrs != NULL) {
      free_wordlist(addrs);
    }
  } else {
    attempts = 0; /* Reset count */
    if (*msg == (char *) 0) {
      *msg = "Login ok";
    }
    *msglen = strlen(*msg);
    set_allowed_addrs(unit, addrs);
  }

  BZERO(passwd, sizeof(passwd));
  BZERO(secret, sizeof(secret));

  return ret;
#endif
}
Beispiel #30
0
void* default_unli_fetcher (void* arg)
{
    void* retr = NULL;
    std::vector<std::string> list;
    std::string pattern = std::string(Config::getLocalDir()) + std::string("/*Gi*.csv");
    default_unli_t default_unli;

    if (OraDBDefaultUnli::init_lib() < 0) {
        LOG_CRITICAL("%s: Unable to initialize libsqlora8!", __func__);
        DO_ABORT();
        return retr;
    }

    OraDBDefaultUnli conn;
    if (conn.initialize(Config::getOraAuth()) < 0) {
        LOG_CRITICAL("%s: Unable to connect to db (%s).", __func__, Config::getOraAuth());
        DO_ABORT();
        return retr;
    }

    LOG_INFO("%s: Started.", __func__);
    LOG_INFO("%s: processing %s files.", __func__, pattern.c_str());

    while (! IS_SHUTDOWN()) {
        glob(list,  pattern);
        //LOG_DEBUG("%s: got %d files.", __func__, list.size());

        for (size_t i=0; i < list.size(); ++i) {
            std::string &src = list[i];
            std::string filename = basename(src);

            //-- check if already processed...
            memset(&default_unli, 0, sizeof(default_unli_t));
            snprintf(default_unli.filename, sizeof(default_unli.filename), "%s", filename.c_str());

            if (conn.getLastFileProcessed(&default_unli) < 0) {
                LOG_ERROR("%s: Unable to get last default_unli file: retr: %d, filename: %s", __func__
                        , default_unli.db_retr, default_unli.filename);
            } else {
                int status = default_unli.db_retr;
                if (1 != status) {
                    LOG_DEBUG("%s: Ignoring previously processed file: %s", __func__, default_unli.filename);
                }

                std::string processed = Config::getLocalProcessedDir() + filename;
                std::string ignored = Config::getLocalIgnoredDir() + filename;
                std::string &dest = (1 == status) ? processed : ignored;

                if (0 != mv(src, dest)) {
                    LOG_ERROR("%s: Unable to move '%s' to '%s'", __func__, src.c_str(), dest.c_str());
                }
            }
        }
        
        //-- sleep for a while
        sys_msleep(1000);
    }

    LOG_INFO("%s: Terminated.", __func__);

    conn.destroy_db();

    return retr;
}