Ejemplo n.º 1
0
/*
 * This function does the actual read of the EEPROM. It needs the buffer into which the
 * read data is copied, the size of the EEPROM being read and the buffer size
 */
int read_eeprom(char *buffer, int eeprom_size, int size)
{
	int	i = 0, err;

	send_start();
	send_byte(W_HEADER);
	recv_ack();

	/* EEPROM with size of more than 2K need two byte addressing */
	if (eeprom_size > 2048) {
		send_byte(0x00);
		recv_ack();
	}

	send_start();
	send_byte(R_HEADER);
	err = recv_ack();
	if (err == -1)
		return err;

	for (i = 0; i < size; i++) {
		*buffer++ = recv_byte();
		send_ack();
	}

	/* Note : We should do some check if the buffer contains correct information */

	send_stop();
}
Ejemplo n.º 2
0
/*-----------------------------------------------------------------------
 * Read bytes
 */
int  i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
{
	int shift;
	PRINTD("i2c_read: chip %02X addr %02X alen %d buffer %p len %d\n",
		chip, addr, alen, buffer, len);

#ifdef CFG_I2C_EEPROM_ADDR_OVERFLOW
	/*
	 * EEPROM chips that implement "address overflow" are ones
	 * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
	 * address and the extra bits end up in the "chip address"
	 * bit slots. This makes a 24WC08 (1Kbyte) chip look like
	 * four 256 byte chips.
	 *
	 * Note that we consider the length of the address field to
	 * still be one byte because the extra address bits are
	 * hidden in the chip address.
	 */
	chip |= ((addr >> (alen * 8)) & CFG_I2C_EEPROM_ADDR_OVERFLOW);

	PRINTD("i2c_read: fix addr_overflow: chip %02X addr %02X\n",
		chip, addr);
#endif

	/*
	 * Do the addressing portion of a write cycle to set the
	 * chip's address pointer.  If the address length is zero,
	 * don't do the normal write cycle to set the address pointer,
	 * there is no address pointer in this chip.
	 */
	send_start();
	if(alen > 0) {
		if(write_byte(chip << 1)) {	/* write cycle */
			send_stop();
			PRINTD("i2c_read, no chip responded %02X\n", chip);
			return(1);
		}
		shift = (alen-1) * 8;
		while(alen-- > 0) {
			if(write_byte(addr >> shift)) {
				PRINTD("i2c_read, address not <ACK>ed\n");
				return(1);
			}
			shift -= 8;
		}
		send_stop();	/* reportedly some chips need a full stop */
		send_start();
	}
	/*
	 * Send the chip address again, this time for a read cycle.
	 * Then read the data.  On the last byte, we do a NACK instead
	 * of an ACK(len == 0) to terminate the read.
	 */
	write_byte((chip << 1) | 1);	/* read cycle */
	while(len-- > 0) {
		*buffer++ = read_byte(len == 0);
	}
	send_stop();
	return(0);
}
Ejemplo n.º 3
0
int clock_main(int argc, char *argv[])
{
  send_start(3000);

  while (1) {
    kz_recv(MSGBOX_ID_TIMEXPIRE, NULL, NULL);
    send_write("ready.\n");
    send_start(3000);
  }

  return 0;
}
Ejemplo n.º 4
0
int i2c_master_tx_rx(uint8_t addr, uint8_t *tx_data, int tx_len, uint8_t *rx_data, int rx_len)
{
	int i;

	I2C0_SA = addr; // Set the slave addr

	I2C0_CNT = tx_len & 0xFF; // Set the tx data count
	I2C0_CON |= (1 << 9) | (1 << 10); // Set the Master Tx mode
	if (send_start()) I2C_QUIT_OP; // Trigger by sending Start
	for (i = 0; i < tx_len; i++) // Send Data
	{
		if (send_data(tx_data[i])) I2C_QUIT_OP;
	}
	while (!(I2C0_IRQSTATUS & I2C_ST_AR)) // Wait for ready for accessing registers after the tx complete
		;
	I2C0_IRQSTATUS |= I2C_ST_AR;
	I2C0_CNT = rx_len & 0xFF; // Set the rx data count
	I2C0_CON &= ~(1 << 9); // Set the Master Rx mode - note master is already set
	if (send_restart()) I2C_QUIT_OP; // Trigger by sending Start again
	for (i = 0; i < rx_len; i++) // Receive Data
	{
		if (recv_data(&rx_data[i])) I2C_QUIT_OP;
	}
	send_stop(); // Done, so Stop
	return 0;
}
Ejemplo n.º 5
0
/**
 * Called at the very start of a request.
 *
 * The request can be either a single request, or a chain of two.  The chaining
 * of requests (with a REPEATED START) is handled later in the interrupt
 * handler.
 */
static void start_request(struct TWI *me)
{
	Q_ASSERT( ! me->requestIndex );
	/*
	SERIALSTR("TWI &request=");
	serial_send_hex_int((uint16_t)(me->requests[0]));
	SERIALSTR(" addr=");
	serial_send_hex_int(me->requests[0]->address & 0xfe);
	if (me->requests[0]->address & 0b1) {
		SERIALSTR("(r)");
	} else {
		SERIALSTR("(w)");
	}
	SERIALSTR(" nbytes=");
	serial_send_int(me->requests[0]->nbytes);
	SERIALSTR("\r\n");
	if (me->requests[1]) {
		SERIALSTR("    &request=");
		serial_send_hex_int((uint16_t)(me->requests[1]));
		SERIALSTR(" addr=");
		serial_send_hex_int(me->requests[1]->address & 0xfe);
		if (me->requests[1]->address & 0b1) {
			SERIALSTR("(r)");
		} else {
			SERIALSTR("(w)");
		}
		SERIALSTR(" nbytes=");
		serial_send_int(me->requests[1]->nbytes);
		SERIALSTR("\r\n");
	}
	serial_drain();
	*/
	me->requests[0]->count = 0;
	send_start(me);
}
Ejemplo n.º 6
0
void handle_delete_character( Network::Client* client, PKTIN_83* msg )
{
  u32 charidx = cfBEu32( msg->charidx );

  if ( ( charidx >= Plib::systemstate.config.character_slots ) || ( client->acct == nullptr ) ||
       ( client->acct->get_character( charidx ) == nullptr ) )
  {
    send_login_error( client, LOGIN_ERROR_MISC );
    client->Disconnect();
    return;
  }

  Accounts::Account* acct = client->acct;
  Mobile::Character* chr = acct->get_character( charidx );
  if ( chr->client != nullptr || ( !Plib::systemstate.config.allow_multi_clients_per_account &&
                                   acct->has_active_characters() ) )
  {
    send_login_error( client, LOGIN_ERROR_OTHER_CHAR_INUSE );
    client->Disconnect();
    return;
  }

  if ( can_delete_character( chr, DELETE_BY_PLAYER ) )
  {
    call_ondelete_scripts( chr );
    delete_character( acct, chr, charidx );
  }

  send_start( client );
}
Ejemplo n.º 7
0
void SerialAPI::do_send(const unsigned char msg) 
{
    bool write_in_progress = !send_msg.empty(); // is there anything currently being written? 
    send_msg.push_back(msg); // store in write buffer 
    if (!write_in_progress) // if nothing is currently being written, then start 
        send_start(); 
} 
Ejemplo n.º 8
0
/*-----------------------------------------------------------------------
 * Write bytes
 */
int  i2c_write(uchar chip, uint addr, int alen, const uchar *buffer, int len)
{
	int shift, failures = 0;

	PRINTD("i2c_write: chip %02X addr %02X alen %d buffer %p len %d\n",
		chip, addr, alen, buffer, len);

	send_start();
	if(write_byte(chip << 1)) {	/* write cycle */
		send_stop();
		PRINTD("i2c_write, no chip responded %02X\n", chip);
		return(1);
	}
	shift = (alen-1) * 8;
	while(alen-- > 0) {
		if(write_byte(addr >> shift)) {
			PRINTD("i2c_write, address not <ACK>ed\n");
			return(1);
		}
		shift -= 8;
	}

	while(len-- > 0) {
		if(write_byte(*buffer++)) {
			failures++;
		}
	}
	send_stop();
	return(failures);
}
Ejemplo n.º 9
0
int fsa9480_i2c_write(u8 addr, u8 data)
{
	u8 chip = 0x4A;


	send_start();
	if (write_byte(chip << 1)) 	/* write cycle */
	{
		send_stop();
//		dprintf(INFO,"i2c_write, no chip responded %02X\n", chip);
		return(1);
	}
	if (write_byte(addr)) 
	{
//		dprintf(INFO,"i2c_write, address not <ACK>\n");
		return(1);
	}
	
	if (write_byte(data)) 
	{
//		dprintf(INFO,"i2c_write, data not <ACK>\n");
		return(1);
	}
	send_stop();

	return 0;	
}
Ejemplo n.º 10
0
irom static i2c_error_t send_header(int address, i2c_direction_t direction)
{
	i2c_error_t error;
	bool_t ack;

	if(state != i2c_state_header_send)
		return(i2c_error_invalid_state_not_send_header);

	address <<= 1;
	address |= direction == i2c_direction_receive ? 0x01 : 0x00;

	state = i2c_state_start_send;

	if((error = send_start()) != i2c_error_ok)
		return(error);

	state = i2c_state_address_send;

	if((error = send_byte(address)) != i2c_error_ok)
		return(error);

	state = i2c_state_address_ack_receive;

	if((error = receive_ack(&ack)) != i2c_error_ok)
		return(error);

	state = i2c_state_address_ack_received;

	if(!ack)
		return(i2c_error_address_nak);

	return(i2c_error_ok);
}
Ejemplo n.º 11
0
static void
sig_composing_start(XMPP_SERVER_REC *server, const char *dest)
{
	DATALIST_REC *rec;

	g_return_if_fail(IS_XMPP_SERVER(server));
	g_return_if_fail(dest != NULL);
	if ((rec = datalist_find(composings, server, dest)) != NULL)
		send_start(server, dest, rec->data);
}
Ejemplo n.º 12
0
void read_pcap(char *pwd)
{
	send_start();
	int re=pcap_loop(pcap,-1,callback,pwd);
	if(re<0)
	{
		fputs("pcap_loop error\n",stdout);
		exit(1);
	}
}
Ejemplo n.º 13
0
void SerialAPI::send_complete(const boost::system::error_code& error) 
{ // the asynchronous read operation has now completed or failed and returned an error 
    if (!error) 
    { // write completed, so send next write data 
        send_msg.pop_front(); // remove the completed data 
        if (!send_msg.empty()) // if there is anything left to be written 
            send_start(); // then start sending the next item in the buffer 
    } 
    else 
        do_close(error); 
} 
Ejemplo n.º 14
0
/*-----------------------------------------------------------------------
 * Probe to see if a chip is present.  Also good for checking for the
 * completion of EEPROM writes since the chip stops responding until
 * the write completes (typically 10mSec).
 */
int i2c_probe(uchar addr)
{
	int rc;

	/*
	 * perform 1 byte write transaction with just address byte
	 * (fake write)
	 */
	send_start();
	rc = write_byte ((addr << 1) | 0);
	send_stop();

	return (rc ? 1 : 0);
}
Ejemplo n.º 15
0
int command_main(int argc, char *argv[])
{
  char *p;
  int size;
  long prev_time;

  send_use(SERIAL_DEFAULT_DEVICE);

  while (1) {
    send_write("command> "); /* プロンプト表示 */

    /* コンソールからの受信文字列を受け取る */
    kz_recv(MSGBOX_ID_CONSINPUT, &size, &p);
    if (p == NULL) {
      send_write("expired.\n");
      continue;
    }
    p[size] = '\0';

    if (!strncmp(p, "echo", 4)) { /* echoコマンド */
      send_write(p + 4); /* echoに続く文字列を出力する */
      send_write("\n");
    } else if (!strncmp(p, "timer", 5)) { /* timerコマンド */
      send_write("timer start.\n");
      send_start(1000);
    } else if (!strncmp(p, "ping", 4)) { /* pingコマンド */
      send_write("ping start.\n");
      send_icmp();
    } else if (!strncmp(p, "tftp", 4)) { /* tftpコマンド */
      send_write("tftp start.\n");
      send_tftp();
    } else if (!strncmp(p, "debug", 5)) { /* デバッガ起動 */
      set_debug_traps();
      force_break();
    } else if (!strncmp(p, "call", 4)) { /* ダミー関数の呼び出し */
      send_write(func(p + 4));
    } else if (!strncmp(p, "get", 3)) { /* get */
      prev_time = get_time();
      putxval(prev_time, 8); puts("\n");
    } else {
      send_write("unknown.\n");
    }

    kz_kmfree(p);
  }

  return 0;
}
Ejemplo n.º 16
0
int i2c_master_tx(uint8_t addr, uint8_t *data, int len)
{
	int i;

	I2C0_SA = addr; // Set the slave addr

	I2C0_CNT = len & 0xFF; // Set the data count
	I2C0_CON |= (1 << 9) | (1 << 10); // Set the Master Tx mode
	if (send_start()) I2C_QUIT_OP; // Trigger by sending Start
	for (i = 0; i < len; i++)
	{
		if (send_data(data[i])) I2C_QUIT_OP;
	}
	send_stop(); // Done, so Stop
	return 0;
}
Ejemplo n.º 17
0
SendControlStatus
DataLink::send_control(const DataSampleHeader& header, ACE_Message_Block* message)
{
  DBG_ENTRY_LVL("DataLink", "send_control", 6);

  TransportSendControlElement* const elem =
    TransportSendControlElement::alloc(1, // initial_count
                                       GUID_UNKNOWN, &send_response_listener_,
                                       header, message, send_control_allocator_);
  if (!elem) return SEND_CONTROL_ERROR;

  send_response_listener_.track_message();

  RepoId senderId(header.publication_id_);
  send_start();
  send(elem);
  send_stop(senderId);

  return SEND_CONTROL_OK;
}
Ejemplo n.º 18
0
Archivo: main.c Proyecto: ChyLau/school
int main (void)
{
    init_leds();
    init();

    send_start();
    is_check();
    send_slave_write();
    is_check();
    send_data();
    is_check();

    while (1)
    {
        send_repeat_start();
        is_check();
        send_slave_read();
        is_check();
        receive_data();
        is_check();
        set_leds(read_data());
        //delay_ms(100);
    }
}
Ejemplo n.º 19
0
int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
	     uint8_t *in, int in_bytes, int flags)
{
	int started = (flags & I2C_XFER_START) ? 0 : 1;
	int rv = EC_SUCCESS;
	int i;

	ASSERT(out || !out_bytes);
	ASSERT(in || !in_bytes);

	dump_i2c_reg(port, "xfer start");

	/*
	 * Clear status
	 *
	 * TODO(crosbug.com/p/29314): should check for any leftover error
	 * status, and reset the port if present.
	 */
	STM32_I2C_SR1(port) = 0;

	/* Clear start, stop, POS, ACK bits to get us in a known state */
	STM32_I2C_CR1(port) &= ~(STM32_I2C_CR1_START |
				 STM32_I2C_CR1_STOP |
				 STM32_I2C_CR1_POS |
				 STM32_I2C_CR1_ACK);

	/* No out bytes and no in bytes means just check for active */
	if (out_bytes || !in_bytes) {
		if (!started) {
			rv = send_start(port, slave_addr);
			if (rv)
				goto xfer_exit;
		}

		/* Write data, if any */
		for (i = 0; i < out_bytes; i++) {
			/* Write next data byte */
			STM32_I2C_DR(port) = out[i];
			dump_i2c_reg(port, "wrote data");

			rv = wait_sr1(port, STM32_I2C_SR1_BTF);
			if (rv)
				goto xfer_exit;
		}

		/* Need repeated start condition before reading */
		started = 0;

		/* If no input bytes, queue stop condition */
		if (!in_bytes && (flags & I2C_XFER_STOP))
			STM32_I2C_CR1(port) |= STM32_I2C_CR1_STOP;
	}

	if (in_bytes) {
		/* Setup ACK/POS before sending start as per user manual */
		if (in_bytes == 2)
			STM32_I2C_CR1(port) |= STM32_I2C_CR1_POS;
		else if (in_bytes != 1)
			STM32_I2C_CR1(port) |= STM32_I2C_CR1_ACK;

		if (!started) {
			rv = send_start(port, slave_addr | 0x01);
			if (rv)
				goto xfer_exit;
		}

		if (in_bytes == 1) {
			/* Set stop immediately after ADDR cleared */
			if (flags & I2C_XFER_STOP)
				STM32_I2C_CR1(port) |= STM32_I2C_CR1_STOP;

			rv = wait_sr1(port, STM32_I2C_SR1_RXNE);
			if (rv)
				goto xfer_exit;

			in[0] = STM32_I2C_DR(port);
		} else if (in_bytes == 2) {
			/* Wait till the shift register is full */
			rv = wait_sr1(port, STM32_I2C_SR1_BTF);
			if (rv)
				goto xfer_exit;

			if (flags & I2C_XFER_STOP)
				STM32_I2C_CR1(port) |= STM32_I2C_CR1_STOP;

			in[0] = STM32_I2C_DR(port);
			in[1] = STM32_I2C_DR(port);
		} else {
			/* Read all but last three */
			for (i = 0; i < in_bytes - 3; i++) {
				/* Wait for receive buffer not empty */
				rv = wait_sr1(port, STM32_I2C_SR1_RXNE);
				if (rv)
					goto xfer_exit;

				dump_i2c_reg(port, "read data");
				in[i] = STM32_I2C_DR(port);
				dump_i2c_reg(port, "post read data");
			}

			/* Wait for BTF (data N-2 in DR, N-1 in shift) */
			rv = wait_sr1(port, STM32_I2C_SR1_BTF);
			if (rv)
				goto xfer_exit;

			/* No more acking */
			STM32_I2C_CR1(port) &= ~STM32_I2C_CR1_ACK;
			in[i++] = STM32_I2C_DR(port);

			/* Wait for BTF (data N-1 in DR, N in shift) */
			rv = wait_sr1(port, STM32_I2C_SR1_BTF);
			if (rv)
				goto xfer_exit;

			/* If this is the last byte, queue stop condition */
			if (flags & I2C_XFER_STOP)
				STM32_I2C_CR1(port) |= STM32_I2C_CR1_STOP;

			/* Read the last two bytes */
			in[i++] = STM32_I2C_DR(port);
			in[i++] = STM32_I2C_DR(port);
		}
	}

 xfer_exit:
	/* On error, queue a stop condition */
	if (rv) {
		flags |= I2C_XFER_STOP;
		STM32_I2C_CR1(port) |= STM32_I2C_CR1_STOP;
		dump_i2c_reg(port, "stop after error");

		/*
		 * If failed at sending start, try resetting the port
		 * to unwedge the bus.
		 */
		if (rv == I2C_ERROR_FAILED_START) {
			const struct i2c_port_t *p = i2c_ports;
			CPRINTS("i2c_xfer start error; "
				"unwedging and resetting i2c %d", port);

			i2c_unwedge(port);

			for (i = 0; i < i2c_ports_used; i++, p++) {
				if (p->port == port) {
					i2c_init_port(p);
					break;
				}
			}
		}
	}

	/* If a stop condition is queued, wait for it to take effect */
	if (flags & I2C_XFER_STOP) {
		/* Wait up to 100 us for bus idle */
		for (i = 0; i < 10; i++) {
			if (!(STM32_I2C_SR2(port) & STM32_I2C_SR2_BUSY))
				break;
			udelay(10);
		}

		/*
		 * Allow bus to idle for at least one 100KHz clock = 10 us.
		 * This allows slaves on the bus to detect bus-idle before
		 * the next start condition.
		 */
		udelay(10);
	}

	return rv;
}
Ejemplo n.º 20
0
void login2( Network::Client* client, PKTIN_91* msg )  // Gameserver login and character listing
{
  client->encrypt_server_stream = true;

  if ( Network::is_banned_ip( client ) )
  {
    send_login_error( client, LOGIN_ERROR_ACCOUNT_BLOCKED );
    client->Disconnect();
    return;
  }

  /* Hmm, might have to re-search for account.
     For now, we already have the account in client->acct.
     Might work different if real loginservers were used. */
  Accounts::Account* acct = Accounts::find_account( msg->name );
  if ( acct == nullptr )
  {
    send_login_error( client, LOGIN_ERROR_NO_ACCOUNT );
    client->Disconnect();
    return;
  }

  // First check the password - if wrong, you can't find out anything else.
  bool correct_password = false;

  // dave changed 6/5/3, always authenticate with hashed user+pass
  std::string msgpass = msg->password;
  std::string acctname = acct->name();
  std::string temp;
  Clib::MD5_Encrypt( acctname + msgpass, temp );  // MD5
  correct_password = Clib::MD5_Compare( acct->passwordhash(), temp );

  if ( !correct_password )
  {
    send_login_error( client, LOGIN_ERROR_WRONG_PASSWORD );
    client->Disconnect();
    POLLOG.Format( "Incorrect password for account {} from {}\n" )
        << acct->name() << client->ipaddrAsString();
    return;
  }
  else
  {
    // write out cleartext if necessary
    if ( Plib::systemstate.config.retain_cleartext_passwords )
    {
      if ( acct->password().empty() )
        acct->set_password( msgpass );
    }
  }

  if ( !acct->enabled() || acct->banned() )
  {
    send_login_error( client, LOGIN_ERROR_ACCOUNT_BLOCKED );
    client->Disconnect();
    return;
  }

  //
  // Dave moved the max_clients check to pol.cpp so character cmdlevel could be checked.
  //

  POLLOG.Format( "Account {} logged in from {}\n" )
      << acct->name() << client->ipaddrAsString();

  // ENHANCEMENT: could authenticate with real loginservers.

  client->acct = acct;
  /* NOTE: acct->client is not set here.  It is possible that another client
     is still connected, or a connection is stuck open, or similar.  When
     a character is selected, if another client is connected, measures will
     be taken. */

  // Tell the client about the starting locations and his characters (up to 5).

  // MuadDib Added new seed system. This is for transferring KR/6017/Normal client detection from
  // loginserver
  // to the gameserver. Allows keeping client flags from remote loginserver to gameserver for 6017
  // and kr
  // packets.
  client->ClientType = cfBEu16( msg->unk3_4_ClientType );

  send_start( client );
}
Ejemplo n.º 21
0
Archivo: fcserver.c Proyecto: C3MA/fc_c
fcserver_ret_t fcserver_process (fcserver_t* server)
{
	int client = 0;
	int i;
	int newClientStarting = 0;
	
	/* Check for new waiting clients */
	if (server == 0 || server->serversocket <= 0)
	{
		return FCSERVER_RET_PARAMERR;
	}
		
	/* Check if a new client can get the wall */
	for (i=0; i < FCSERVER_MAXCLIENT; i++)
	{
		/* search for already connected clients */
		if (server->client[i].clientstatus == FCCLIENT_STATUS_CONNECTED)
		{
			client = 1; /* reusing variable as flag to indicate an already connected client */
		}
		else if (newClientStarting == 0 && server->client[i].clientstatus == FCCLIENT_STATUS_WAITING)
		{
			/* Client %d is waiting", i */
			newClientStarting = (i + 1); /* count from 1 to FCSERVER_MAXCLIENT + 1 */
		}
	}
	
	if (!client)
	{
		/* no-one is actual using the wall, a new one can start now */
		if (newClientStarting) /* as the index starts at one we can detect here new clients */
		{
			int write_offset = 0;
			DEBUG_PLINE("Client %d has now the wall", server->client[newClientStarting - 1].clientsocket);
			server->client[newClientStarting - 1].clientstatus = FCCLIENT_STATUS_CONNECTED;
			
			if (server->onClientChange > 0)
			{
				server->onClientChange(server->clientcount, FCCLIENT_STATUS_CONNECTED, 
									   server->client[newClientStarting - 1].clientsocket);
			}
			
			/* allocate some memory for answering */
			uint8_t *output = hwal_malloc(BUFFERSIZE_OUTPUT); hwal_memset(output, 0, BUFFERSIZE_OUTPUT);
			uint8_t *buffer = hwal_malloc(BUFFERSIZE_SENDINGBUFFER); hwal_memset(output, 0, BUFFERSIZE_SENDINGBUFFER);
			
			write_offset = send_start(buffer, write_offset);
			
			/* send the corresponding message: Success or error */
			add_header(buffer, output, write_offset);
			hwal_socket_tcp_write(server->client[newClientStarting - 1].clientsocket, output, write_offset+HEADER_LENGTH);
			
			hwal_free(buffer);
			hwal_free(output);
		}
	}
	client = 0; /* Reset the temporary variable, for the original porpuse */
	
	/** handle all actual connected clients **/
	/* search for new waiting ones */
	client = hwal_socket_tcp_accet(server->serversocket);
	
	if (client > 0)
	{
		if (server->clientcount < (FCSERVER_MAXCLIENT - 1))
		{
			server->clientcount++;
			store_client_in(server, client);
			
			if (server->onClientChange > 0)
			{
				server->onClientChange(server->clientcount, FCCLIENT_STATUS_INITING, client);
			}
		}
		else
		{
			uint8_t buffer[BUFFERSIZE_SENDINGBUFFER];
			/* Inform the client with an error message */
			char descr[] = "No Space for new client";
			int write_offset = 0;
			
			uint8_t *output = hwal_malloc(BUFFERSIZE_OUTPUT); hwal_memset(output, 0, BUFFERSIZE_OUTPUT);
			
			write_offset = send_error(buffer, write_offset, FCSERVER_ERR_MAXCLIENTS, descr);			
			DEBUG_PLINE("No Space for new client");			
			/* send the corresponding message: Success or error */
			add_header(buffer, output, write_offset);
			hwal_socket_tcp_write(client, output, write_offset+HEADER_LENGTH);			
			hwal_socket_tcp_close(client);
			
			if (server->onClientChange > 0)
			{
				server->onClientChange(server->clientcount, FCCLIENT_STATUS_TOOMUTCH, client);
			}
		}
	}
	
	/* handle all open connections */
	for (i=0; i < FCSERVER_MAXCLIENT; i++)
	{
		if (server->client[i].clientsocket > 0)
		{
			/* Found an open client ... speak with him */
			if (process_client(server, &(server->client[i]) ) == FCSERVER_RET_CLOSED)
			{
				DEBUG_PLINE("Client with socket %d closed", server->client[i].clientsocket);
				if (server->onClientChange > 0)
				{
					server->onClientChange(server->clientcount, 
										   FCCLIENT_STATUS_DISCONNECTED, 
										   server->client[i].clientsocket);
				}
				hwal_memset( &(server->client[i]), 0, sizeof(fcclient_t) );
				server->clientcount--;				
			}
		}
	}
	
	
	return FCSERVER_RET_OK;
}