Exemplo n.º 1
0
/*----------------------------------------------------------------------------*/
int nxp_get_wait(ASerialPort_t* aPort, char* aBuff, int aSize, int aWait)
{
	int count = 0;
	byte_t test;
	char *buff = malloc(aSize);
	while(!check_incoming(aPort));
	while(count<aWait||check_incoming(aPort))
	{
		while(!check_incoming(aPort));
		test = get_byte_serial(aPort);
#ifdef MY1DEBUG
		putchar(test);
#endif
		if(count<aSize-1)
			buff[count] = test;
		count++;
	}
	if(count<aSize) buff[count] = 0x0;
	else buff[aSize-1] = 0x0;
	sscanf(buff,"%s",aBuff);
#ifdef MY1DEBUG
	printf("BUFF:'%s', CHECK:%d/%d\n",aBuff,count,aWait);
#endif
	free(buff);
	return count < aSize ? 0 : count;
}
Exemplo n.º 2
0
/*----------------------------------------------------------------------------*/
int bcheck_device(ASerialPort_t* aPort, ADeviceNXP_t* aDevice)
{
	int test;
	printf("Device blank check... ");
	test = nxp_blank_check(aPort,aDevice);
	if(test)
	{
		printf("Cannot check device blank status!\n");
		return ERROR_GENERAL;
	}
	if(!aDevice->do_acknowledge)
	{
		byte_t temp;
		int size = strlen(aDevice->hexstr);
		while(check_incoming(aPort))
		{
			temp = get_byte_serial(aPort);
			if (size==COUNT_HEXSTR_BUFF-1)
			{
				aDevice->hexstr[size] = 0x0;
				continue;
			}
			aDevice->hexstr[size++] = temp;
		}
		aDevice->hexstr[size] = 0x0;
		printf(" [OK] Device NOT blank ('%s'){%d}!\n",aDevice->hexstr,size);
		return ERROR_GENERAL;
	}
	printf(" [OK] Device is blank!\n");
	return test;
}
Exemplo n.º 3
0
static int mpoa_egress_cache_purge_reply( uint8_t * buff ){
  int pos = 0;
  struct nhrp_fixed_h *fixed = (struct nhrp_fixed_h *)buff;
  struct nhrp_common_h *common;
  struct nhrp_cie *cie;
  struct extension_values values;
  struct k_message msg;
  memset(&values, 0, sizeof(struct extension_values));
  memset(&msg,0,sizeof(struct k_message));
  pos += sizeof(struct nhrp_fixed_h);
  common = (struct nhrp_common_h*)(buff + pos);
  if(!check_incoming(ntohl(common->request_ID), MPOA_EGRESS_CACHE_PURGE_REQUEST))
    return -1;
  pos += sizeof(struct nhrp_common_h);
  cie = (struct nhrp_cie *)(buff + pos);
  msg.ip_mask = calculate_ip_mask(cie->prefix_length);
  if(fixed->ar_extoff)
    parse_extensions(buff + ntohs(fixed->ar_extoff),&values);
  else {
    printf("mpcd: p_recogn.c: warning: ");
    printf("no extensions in MPOA Egress Cache Purge Reply\n");
    return -1;
  }
  if (values.dll_header_present == 0) {
    printf("mpcd: p_recogn.c: warning: ");
    printf("DLL Header Extension missing in MPOA Egress Cache Purge Reply\n");
    return -1;
  }
  msg.content.eg_info.cache_id = values.dll_ext.cache_id;
  msg.type = EGRESS_PURGE_RCVD;
  memcpy(msg.MPS_ctrl,mpc_control.MPS_CTRL_ATM_ADDR,ATM_ESA_LEN);
  return send_to_kernel(&msg);
}
Exemplo n.º 4
0
/*----------------------------------------------------------------------------*/
int nxp_check_isp(ASerialPort_t* aPort, ADeviceNXP_t* aDevice)
{
	my1key_t key;
	char nxp_sync_char = aDevice ? aDevice->sync_char : NXP_SYNC_CHAR;
	int status = NXP_CHECK_START;
	flush_serial(aPort);
	purge_serial(aPort);
	while(status<NXP_CHECK_FOUND)
	{
		put_byte_serial(aPort,nxp_sync_char);
		wait_outgoing(aPort);
		if(check_incoming(aPort))
		{
			byte_t test = get_byte_serial(aPort);
			if(test==nxp_sync_char)
			{
				status = NXP_CHECK_FOUND;
				break;
			}
		}
		key = get_keyhit();
		if(key==KEY_ESCAPE)
			status = NXP_CHECK_ABORT;
		else if(key==KEY_BSPACE)
			status = NXP_CHECK_RESET;
	}
	flush_serial(aPort);
	purge_serial(aPort);
	return status;
}
Exemplo n.º 5
0
/*----------------------------------------------------------------------------*/
int nxp_send_hex(ASerialPort_t* aPort, const char* hexstr)
{
	byte_t test;
	int length = 0, error = 0, loop;
	while(hexstr[length]) length++;
#ifdef MY1DEBUG
	printf("Length=%d, HexStr='%s'\n",length,hexstr);
#endif
	purge_serial(aPort);
	for(loop=0;loop<length;loop++)
	{
		put_byte_serial(aPort, hexstr[loop]);
		while(!check_incoming(aPort));
		test = get_byte_serial(aPort);
		if(test!=hexstr[loop])
		{
#ifdef MY1DEBUG
			printf("Error: '%c' <=> '%c'\n",test,hexstr[loop]);
#endif
			error++;
		}
	}
	/* end with dos newline char pair */
	put_byte_serial(aPort, 0x0d); /* cr */
	put_byte_serial(aPort, 0x0a); /* lf */
	return error;
}
Exemplo n.º 6
0
static void
comm_call_slowfds(void)
{
    while (n_slow_fds) {
	int i = (squid_random() % n_slow_fds) + 1;
	int fd = slow_fds[i];
	fde *F = &fd_table[fd];
	commRemoveSlow(fd);
	if (F->read_handler) {
	    PF *hdl = F->read_handler;
	    void *hdl_data = F->read_data;
	    debug(5, 8) ("comm_call_handlers(): Calling read handler on fd=%d\n", fd);
#if SIMPLE_COMM_HANDLER
	    commUpdateReadHandler(fd, NULL, NULL);
	    commResumeFD(fd);
	    hdl(fd, hdl_data);
#else
	    /* Optimized version to avoid the fd bouncing in/out of the waited set */
	    F->read_handler = NULL;
	    F->read_data = NULL;
	    F->read_pending = COMM_PENDING_NORMAL;
	    hdl(fd, hdl_data);
	    /* backoff check is for delayed connections kicked alive from checkTimeouts */
	    if (F->flags.open && (!F->read_handler || F->flags.backoff)) {
		if (F->flags.backoff && commDeferRead(fd) != 1)
		    F->flags.backoff = 0;
		commUpdateEvents(fd);
	    }
#endif
	    statCounter.select_fds++;
	    check_incoming();
	}
    }
}
Exemplo n.º 7
0
static int mpoa_resolution_reply( uint8_t * buff ){
  int pos = 0;
  struct k_message msg;
  struct extension_values values;
  struct nhrp_common_h *common;
  struct nhrp_cie *cie;
  struct nhrp_fixed_h *fixed = (struct nhrp_fixed_h*)buff;
  memset(&values, 0, sizeof(struct extension_values));
  memset(&msg,0,sizeof(struct k_message));
  pos += sizeof(struct nhrp_fixed_h);
  common = (struct nhrp_common_h*)(buff + pos);
  if(!check_incoming(ntohl(common->request_ID),MPOA_RESOLUTION_REQUEST))
    return -1;
  pos += sizeof(struct nhrp_common_h);
  cie = (struct nhrp_cie*)(buff + pos);
  if(cie->code){
    print_cie_code(cie->code);
    return -1;
  }
  msg.content.in_info.holding_time = ntohs(cie->holding_time);
  if(fixed->ar_extoff)
    pos += parse_extensions(buff + ntohs(fixed->ar_extoff), &values);
  if (values.egress_cache_tag_ext_present == 0) {
          printf("mpcd: p_recogn.c: warning: ");
          printf("received MPOA Resolution Reply ");
          printf("with no Egress Cache Tag Extension\n");
  }
  if(values.tag_present && values.tag == 0) {
          printf("mpcd: p_recogn.c: warning: ");
          printf("received MPOA Resolution Reply ");
          printf("with Egress Cache Tag Extension where tag == 0\n");
          values.tag_present = 0;
  }
  if(values.tag_present){
    msg.content.in_info.tag = values.tag;
  }
  msg.type = MPOA_RES_REPLY_RCVD;
  msg.content.in_info.in_dst_ip  = common->dst_protocol_address;
  memcpy(msg.content.in_info.eg_MPC_ATM_addr,cie->cli_nbma_address,ATM_ESA_LEN);
  memcpy(msg.MPS_ctrl,mpc_control.MPS_CTRL_ATM_ADDR, ATM_ESA_LEN);
  if(values.service_category_present)
    msg.qos.txtp.traffic_class = service_category_to_traff_class(values.service_category);
  else
    msg.qos.txtp.traffic_class = ATM_UBR;
  send_to_kernel(&msg);
  keep_alive_sm_running = 1;
  return MPOA_RESOLUTION_REPLY;
}
Exemplo n.º 8
0
// Main
void main (void) {
	init(); // Initialize

	while (1) {

		check_incoming(); // Car enters

		check_outgoing(); // Car leaves
		   
		/**
		 * Create an artificial time delay
		 * Needed so the user can have time to remove his/her finger
		 * from the button before the BUTTON_ENTER == 1 is checked again
		**/
		for (cycle_delay = 0; cycle_delay < cycle_duration; cycle_delay++);

		display(free_slots); // Output the number of free slots
	}
}
Exemplo n.º 9
0
/*----------------------------------------------------------------------------*/
int find_device(ASerialPort_t* aPort, ADeviceNXP_t* aDevice)
{
	int test;
	char nxp_sync_char = aDevice ? aDevice->sync_char : NXP_SYNC_CHAR;
	aDevice->found = 0;
	/** try this once! */
	put_byte_serial(aPort,nxp_sync_char);
	wait_outgoing(aPort);
	usleep(NXP_FIND_WAIT);
	if(check_incoming(aPort))
	{
		byte_t test = get_byte_serial(aPort);
		if(test==nxp_sync_char)
		{
			aDevice->found = 1;
			return NXP_CHECK_FOUND;
		}
	}
	printf("\nReset the NXP device... ");
	test = nxp_check_isp(aPort,aDevice);
	if(test==NXP_CHECK_FOUND)
	{
		aDevice->found = 1;
		printf("NXP device found!\n\n");
	}
	else if(test==NXP_CHECK_RESET)
	{
		aDevice->found = 0;
		printf("User Reset Request!\n\n");
	}
	else /** if(test==NXP_CHECK_ABORT) */
	{
		printf("User Abort Request!\n\n");
	}
	return test;
}
Exemplo n.º 10
0
static void h_xstor(struct context *ctx, char *arg, int flags)
{
    char *t;
    int f = -1;
    struct stat st;
    int stou = 0;
    char tbuf[PATH_MAX + 1];

    DebugIn(DEBUG_COMMAND);

    if (ctx->transfer_in_progress) {
	reply(ctx, MSG_501_Transfer_in_progress);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    ctx->outgoing_data = 0;
    if (ctx->dfn > -1 && io_get_cb_i(ctx->io, ctx->dfn) == (void *) accept_data) {
	io_set_i(ctx->io, ctx->dfn);
	io_clr_o(ctx->io, ctx->dfn);
	io_set_cb_e(ctx->io, ctx->dfn, (void *) cleanup_data);
	io_set_cb_h(ctx->io, ctx->dfn, (void *) cleanup_data);
    }

    quota_add(ctx, 0);

    if (ctx->quota_path && (ctx->quota_ondisk >= ctx->quota_limit)) {
	reply(ctx, MSG_451_quota_exceeded);
	logmsg("%s: quota limit reached", ctx->user);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    if (!arg) {
	stou = -1;
	snprintf(tbuf, sizeof(tbuf), "%s/stou.XXXXXX", ctx->cwd);
	arg = tbuf;

	t = buildpath(ctx, arg);
    } else if (acl_binary_only(ctx, arg, (t = buildpath(ctx, arg)))) {
	reply(ctx, MSG_504_no_ascii);
	cleanup_data_reuse(ctx, ctx->dfn);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    st.st_size = 0;

    if (t)
	acl_set_umask(ctx, arg, t);

    if (ctx->anonymous || stou)
	flags |= O_EXCL;

    if (t && (!ctx->anonymous || check_incoming(ctx, t, 077)) &&
	!pickystat_path(ctx, &st, t) &&
	(stat(t, &st), (f = myopen(t, O_RDWR | O_CREAT | O_LARGEFILE | O_NOFOLLOW | flags, ctx->chmod_filemask | (0644 & ~ctx->umask), stou)) > -1)) {

	fcntl(f, F_SETFD, FD_CLOEXEC);

	ctx->quota_filesize_before_stor = st.st_size;
	ctx->quota_update_on_close = 1;

	if (ctx->dfn < 0)
	    connect_port(ctx);

	if (ctx->dfn < 0) {
	    reply(ctx, MSG_431_Opening_datacon_failed);
	    close(f);
	    ctx->dbuf = buffer_free_all(ctx->dbuf);
	    DebugOut(DEBUG_COMMAND);
	    return;
	}

	ctx->ffn = f;
	if (strlen(t) >= sizeof(ctx->filename)) {
	    logerr("buffer too small in %s:%d (%s/%s)", __FILE__, __LINE__, ctx->user, t);
	    reply(ctx, MSG_551_Internal_error);
	    close(f);
	    cleanup(ctx, ctx->dfn);
	    ctx->dbuf = buffer_free_all(ctx->dbuf);
	    DebugOut(DEBUG_COMMAND);
	    return;
	}
	strcpy(ctx->filename, t);
	ctx->filesize = 0;
	ctx->bytecount = 0;

	if (io_get_cb_i(ctx->io, ctx->dfn) == (void *) socket2buffer || is_connected(ctx->dfn)) {
	    if (stou)
		replyf(ctx, "125 FILE: %s\r\n", ctx->filename + ctx->rootlen);
	    else
		replyf(ctx, MSG_125_Starting_dc, ctx->use_ascii ? "ASCII" : "BINARY", ctx->use_tls_d ? "TLS " : "");
	} else {
	    if (stou)
		replyf(ctx, "150 FILE: %s\r\n", ctx->filename + ctx->rootlen);
	    else
		replyf(ctx, MSG_150_Opening_dc, ctx->use_ascii ? "ASCII" : "BINARY", ctx->use_tls_d ? "TLS " : "");
	}

	ctx->transfer_in_progress = 1;

	if (ctx->io_offset) {
	    if (ctx->use_ascii) {
		ctx->offset = 0;
		ctx->remaining = st.st_size;
		io_sched_add(ctx->io, ctx, (void *) skipbytes, 0, 0);
#ifdef WITH_MMAP
		if (use_mmap)
		    ctx->iomode = IOMODE_mmap;
		else
#endif
		    ctx->iomode = IOMODE_read, ctx->iomode_fixed = 1;
	    } else {
		lseek(f, ctx->io_offset, SEEK_SET);
		ctx->io_offset = 0;
	    }
	}

	if (io_get_cb_i(ctx->io, ctx->dfn) == (void *) socket2buffer) {
	    /* already connected */
	    io_clr_o(ctx->io, ctx->dfn);
	    io_set_i(ctx->io, ctx->dfn);
	}

	ctx->transferstart = io_now.tv_sec;
	ctx->count_files++;
    } else {
	if (stou && errno == EEXIST)
	    reply(ctx, MSG_451_unique_file_failure);
	else
	    reply(ctx, MSG_550_Permission_denied);
	cleanup_data_reuse(ctx, ctx->dfn);
    }

    DebugOut(DEBUG_COMMAND);
}
Exemplo n.º 11
0
// Check UDP for incoming packets
void check_incoming() {
  int packetSize;
  int i;
  int empty = 0;
  int found = -1;

  packetSize = udp.parsePacket();
  if (packetSize) {
    IPAddress remote = udp.remoteIP();
    // read the packet into packetBufffer
    udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    #ifdef DEBUG
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    for (i = 0; i < 4; i++) {
      Serial.print(remote[i], DEC);
      if (i < 3) {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(udp.remotePort());
    Serial.print("Dump: ");
    for (i = 0; i < packetSize / sizeof(uint16_t); i++) {
      Serial.print(*((uint16_t *) (packetBuffer + i * sizeof(uint16_t))));
      Serial.print(" ");
    }
    Serial.println();
    #endif

    // Master sends all packets to its clients and updates cache
    if (my_node_type == MSGMULTI_MASTER) {
      found = -1;
      empty = 0;
      send_packet(packetBuffer, packetSize, remote);
      for (i = 0; i < MSGMULTI_MAXCLIENTS; i++) {
        if (clients[i].client == remote) {
          found = i;
          break;
        }
        if (clients[i].expire <= 0)
          empty = i;
      }
      if (found >= 0)
        clients[found].expire = 1024;
      else {
        clients[empty].client = remote;
        clients[empty].expire = 1024;
      }
    }

    // Process incoming statuses
    for (i = 0; i < *((uint16_t *) packetBuffer); i++) {
      receive_status((struct msgrecord *) (packetBuffer + i * sizeof(struct msgrecord) + sizeof(uint16_t)));
    }

    // Repeat incoming check to process all packets in queue
    check_incoming();
  }

  // Check if we have to repeat last sent statuses
  resend_status();
} // void check_incoming()
Exemplo n.º 12
0
static inline void
comm_call_handlers(int fd, int read_event, int write_event)
{
    fde *F = &fd_table[fd];
    const int do_incoming = read_event == 1 || write_event == 1;
    debug(5, 8) ("comm_call_handlers(): got fd=%d read_event=%x write_event=%x F->read_handler=%p F->write_handler=%p\n"
	,fd, read_event, write_event, F->read_handler, F->write_handler);
    if (F->read_handler) {
	int do_read = 0;
	switch (F->read_pending) {
	case COMM_PENDING_NORMAL:
	case COMM_PENDING_WANTS_READ:
	    do_read = read_event;
	    break;
	case COMM_PENDING_WANTS_WRITE:
	    do_read = write_event;
	    break;
	case COMM_PENDING_NOW:
	    do_read = 1;
	    break;
	}
	if (do_read) {
	    PF *hdl = F->read_handler;
	    void *hdl_data = F->read_data;
	    /* If the descriptor is meant to be deferred, don't handle */
	    switch (commDeferRead(fd)) {
#if DELAY_POOLS
	    case -1:
		commAddSlow(fd);
		break;
#endif
	    default:
		if (!(F->flags.backoff)) {
		    debug(5, 1) ("comm_call_handlers(): WARNING defer handler for fd=%d (desc=%s) does not call commDeferFD() - backing off manually\n", fd, F->desc);
		    commDeferFD(fd);
		}
		break;
	    case 0:
		debug(5, 8) ("comm_call_handlers(): Calling read handler on fd=%d\n", fd);
#if SIMPLE_COMM_HANDLER
		commUpdateReadHandler(fd, NULL, NULL);
		hdl(fd, hdl_data);
#else
		/* Optimized version to avoid the fd bouncing in/out of the waited set */
		F->read_handler = NULL;
		F->read_data = NULL;
		F->read_pending = COMM_PENDING_NORMAL;
		hdl(fd, hdl_data);
		if (F->flags.open && !F->read_handler)
		    commUpdateEvents(fd);
#endif
		statCounter.select_fds++;
		if (do_incoming)
		    check_incoming();
		break;
	    }
	}
    }
    if (F->write_handler) {
	int do_write = 0;
	switch (F->write_pending) {
	case COMM_PENDING_WANTS_READ:
	    do_write = read_event;
	    break;
	case COMM_PENDING_NORMAL:
	case COMM_PENDING_WANTS_WRITE:
	    do_write = write_event;
	    break;
	case COMM_PENDING_NOW:
	    do_write = 1;
	    break;
	}
	if (do_write) {
	    PF *hdl = F->write_handler;
	    void *hdl_data = F->write_data;
#if SIMPLE_COMM_HANDLER
	    commUpdateWriteHandler(fd, NULL, NULL);
	    hdl(fd, hdl_data);
#else
	    /* Optimized version to avoid the fd bouncing in/out of the waited set */
	    F->write_handler = NULL;
	    F->write_data = NULL;
	    F->write_pending = COMM_PENDING_NORMAL;
	    hdl(fd, hdl_data);
	    if (F->flags.open)
		commUpdateEvents(fd);
#endif
	    statCounter.select_fds++;
	    if (do_incoming)
		check_incoming();
	}
    }
}