Esempio n. 1
0
// used to test out the get public data events
void SimpleShell::get_command( string parameters, StreamOutput* stream){
    int what= get_checksum(shift_parameter( parameters ));
    void *returned_data;

    if(what == get_temp_command_checksum) {
        string type= shift_parameter( parameters );
        bool ok= this->kernel->public_data->get_value( temperature_control_checksum, get_checksum(type), current_temperature_checksum, &returned_data );

        if(ok) {
            struct pad_temperature temp=  *static_cast<struct pad_temperature*>(returned_data);
            stream->printf("%s temp: %f/%f @%d\r\n", type.c_str(), temp.current_temperature, temp.target_temperature, temp.pwm);
        }else{
            stream->printf("%s is not a known temperature device\r\n", type.c_str());
        }

    }else if(what == get_pos_command_checksum) {
        bool ok= this->kernel->public_data->get_value( robot_checksum, current_position_checksum, &returned_data );

        if(ok) {
            double *pos= static_cast<double *>(returned_data);
            stream->printf("Position X: %f, Y: %f, Z: %f\r\n", pos[0], pos[1], pos[2]);

        }else{
            stream->printf("get pos command failed\r\n");
        }
    }
}
Esempio n. 2
0
static struct dupl_id *check_id_dupl(struct xattr_list *xattr_list, int xattrs)
{
	struct dupl_id *entry;
	int i;
	unsigned short checksum = 0;

	/* compute checksum over all xattrs */
	for(i = 0; i < xattrs; i++) {
		struct xattr_list *xattr = &xattr_list[i];

		checksum = get_checksum(xattr->full_name,
					strlen(xattr->full_name), checksum);
		checksum = get_checksum(xattr->value,
					xattr->vsize, checksum);
	}

	for(entry = dupl_id[checksum]; entry; entry = entry->next) {
		if (entry->xattrs != xattrs)
			continue;

		for(i = 0; i < xattrs; i++) {
			struct xattr_list *xattr = &xattr_list[i];
			struct xattr_list *dup_xattr = &entry->xattr_list[i];

			if(strcmp(xattr->full_name, dup_xattr->full_name))
				break;

			if(memcmp(xattr->value, dup_xattr->value, xattr->vsize))
				break;
		}
		
		if(i == xattrs)
			break;
	}

	if(entry == NULL) {
		/* no duplicate exists */
		entry = malloc(sizeof(*entry));
		if(entry == NULL) {
			ERROR("malloc failed in check_ip_dupl\n");
			return NULL;
		}
		entry->xattrs = xattrs;
		entry->xattr_list = xattr_list;
		entry->xattr_id = SQUASHFS_INVALID_XATTR;
		entry->next = dupl_id[checksum];
		dupl_id[checksum] = entry;
	}
		
	return entry;
}
Esempio n. 3
0
static void
test_get_checksum_succeeds_if_size_odd_number() {
  buffer *ipv4_buffer = setup_dummy_ether_ipv4_packet( );
  ipv4_header_t *odd_number = ( ipv4_header_t * ) ( ( char * ) ( ipv4_buffer->data ) + sizeof( ether_header_t ) );

  odd_number->check = 0;
  odd_number->check = get_checksum( ( uint16_t * ) odd_number, sizeof( ipv4_header_t ) - 1  );
  assert_true( odd_number->check != 0 );

  odd_number->check = get_checksum( ( uint16_t * ) odd_number, sizeof( ipv4_header_t ) - 1 );
  assert_true( odd_number->check == 0 );

  free_buffer( ipv4_buffer );
}
void checkup::unit_checksum(const map_location& loc, bool local)
{
    unit_map::iterator u =  resources::units->find(loc);
    bool equals;
    config real;
    config expected;

    if (!u.valid()) {
        std::stringstream message;
        message << "non existent unit to checksum at " << loc.x+1 << "," << loc.y+1 << "!";
        resources::screen->add_chat_message(time(NULL), "verification", 1, message.str(),
                                            events::chat_handler::MESSAGE_PRIVATE, false);
    }
    else
    {
        expected["checksum"] = get_checksum(*u);
    }

    if(local)
    {
        equals = local_checkup(expected, real);
    }
    else
    {
        equals = this->networked_checkup(expected, real);
    }

    if(!equals && ((game_config::mp_debug && !local) || local))
    {
        std::stringstream message;
        message << "checksum mismatch at " << loc.x+1 << "," << loc.y+1 << "!";
        resources::screen->add_chat_message(time(NULL), "verification", 1, message.str(),
                                            events::chat_handler::MESSAGE_PRIVATE, false);
    }
}
/**
 * Used to process a data frame that has just been uploaded.
 */
void block_uploaded(struct rx_frame* rx) {
  uint32_t mem_addr;
  uint32_t checksum, actual_checksum;

  if (rx->length >= MEMORY_RECORD_SIZE) {
    /* Copy the record from the radio packet. Skip the header and memory address */
    memcpy(record, rx->data+5, MEMORY_RECORD_SIZE);

    /* Calculate the checksum */
    actual_checksum = calculate_checksum(record);
    /* Read the checksum */
    checksum = get_checksum(record);

    if (checksum == actual_checksum) {
      /* Extract the memory address */
      mem_addr = get_memory_address_from_rx(rx);

      /* Acknowledge the frame */
      send_upload_ack(rx->source_address, mem_addr, checksum);

      /* Write the record out to memory */
      put_sample(record);

      console_puts("Radio Upload Frame OK\n");
    } else {
      console_puts("Radio Upload Frame Checksum Error!\n");
      console_printf("Frame: %04x\nCalc: %04x\n", checksum, actual_checksum);
    }
  } else {
    console_puts("Radio Upload Frame too short!\n");
  }
}
Esempio n. 6
0
// When a new line is received, check if it is a command, and if it is, act upon it
void SimpleShell::on_console_line_received( void* argument ){
    SerialMessage new_message = *static_cast<SerialMessage*>(argument);
    string possible_command = new_message.message;

    //new_message.stream->printf("Received %s\r\n", possible_command.c_str());

    // We don't compare to a string but to a checksum of that string, this saves some space in flash memory
    unsigned short check_sum = get_checksum( possible_command.substr(0,possible_command.find_first_of(" \r\n")) );  // todo: put this method somewhere more convenient

    // Act depending on command
    if (check_sum == ls_command_checksum)
        this->ls_command(  get_arguments(possible_command), new_message.stream );
    else if (check_sum == cd_command_checksum)
        this->cd_command(  get_arguments(possible_command), new_message.stream );
    else if (check_sum == pwd_command_checksum)
        this->pwd_command( get_arguments(possible_command), new_message.stream );
    else if (check_sum == cat_command_checksum)
        this->cat_command( get_arguments(possible_command), new_message.stream );
    else if (check_sum == break_command_checksum)
        this->break_command(get_arguments(possible_command),new_message.stream );
    else if (check_sum == reset_command_checksum)
        this->reset_command(get_arguments(possible_command),new_message.stream );
    else if (check_sum == dfu_command_checksum)
        this->dfu_command(get_arguments(possible_command),new_message.stream );
    else if (check_sum == help_command_checksum)
        this->help_command(get_arguments(possible_command),new_message.stream );
}
Esempio n. 7
0
//-----------------------------------------------------------------------------
int read_data_word ( unsigned int addr, unsigned int *data )
{
    unsigned int ra,rb,rc,rd;

    sprintf((char *)sdata,"R %u 4\r",addr);
    ra=strlen((char *)sdata);
    ser_senddata(sdata,ra);
    if(get_return_code()) return(1);

    ra=wait_for_packet();
    if(ra<3) return(1);


    for(rb=0;rb<ra;rb++) printf("0x%02X ",rdata[rb]); printf("\n");

    rb=uudecode(udata,&rdata[1],ra-2);
    rc=0;
    rd=0;
    for(ra=0;ra<rb;ra++)
    {
        rd<<=8;
        rd|=udata[ra];
        rc+=udata[ra];
        printf("0x%02X %u\n",udata[ra],rc);
    }
    if(get_checksum(&ra)) return(1);
    if(ra!=rc) return(1);
    ser_senddata(okpatt,sizeof(okpatt));
    *data=rd;
    return(0);
}
Esempio n. 8
0
static void ogg_update_checksum(AVFormatContext *s, int64_t crc_offset)
{
    int64_t pos = url_ftell(s->pb);
    uint32_t checksum = get_checksum(s->pb);
    url_fseek(s->pb, crc_offset, SEEK_SET);
    put_be32(s->pb, checksum);
    url_fseek(s->pb, pos, SEEK_SET);
}
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
{
    int64_t pos = avio_tell(pb);
    uint32_t checksum = get_checksum(pb);
    avio_seek(pb, crc_offset, SEEK_SET);
    avio_wb32(pb, checksum);
    avio_seek(pb, pos, SEEK_SET);
}
Esempio n. 10
0
// used to test out the get public data events for switch
void SimpleShell::switch_command( string parameters, StreamOutput *stream)
{
    string type = shift_parameter( parameters );
    string value = shift_parameter( parameters );
    bool ok = false;
    if(value == "on" || value == "off") {
        bool b = value == "on";
        ok = PublicData::set_value( switch_checksum, get_checksum(type), state_checksum, &b );
    } else {
        float v = strtof(value.c_str(), NULL);
        ok = PublicData::set_value( switch_checksum, get_checksum(type), value_checksum, &v );
    }
    if (ok) {
        stream->printf("switch %s set to: %s\r\n", type.c_str(), value.c_str());
    } else {
        stream->printf("%s is not a known switch device\r\n", type.c_str());
    }
}
///////////////////////////// Message receiving /////////////////////////////
Message * receive_message() {
  radio.read(rx_buffer, MESSAGE_LENGTH);
  Message *m = (Message *) rx_buffer;
  if (calculate_checksum(m) != (get_checksum(m))) {
    Serial.println("WARNING: Checksum differs from expected value.");
    m->message_id = ERROR;
  }
  return m;
}
Esempio n. 12
0
bool Fs::fsck(void) {
  fileoffset_t first_empty_byte;
  uint8_t sum = 0xFF;
  filecount_t exists;
  size_t status;

  mtd.read(dbg_super, sizeof(dbg_super), 0);

  /* open superblock */
  osalDbgCheck((this->files_opened == 0) && (nullptr == super.mtd));
  open_super();

  /* check magic */
  get_magic(toc_buf);
  sum = nvramcrc(toc_buf, sizeof(magic), sum);
  if (0 != memcmp(magic, toc_buf, sizeof(magic)))
    goto FAILED;

  /* check existing files number */
  exists = get_file_cnt();
  sum = nvramcrc(&exists, sizeof(exists), sum);
  if (exists > NVRAM_FS_MAX_FILE_CNT)
    goto FAILED;

  /* verify check sum */
  for (size_t i=0; i<NVRAM_FS_MAX_FILE_CNT; i++){
    status = super.read(toc_buf, sizeof(toc_buf));
    osalDbgCheck(sizeof(toc_buf) == status);
    sum = nvramcrc(toc_buf, sizeof(toc_buf), sum);
  }
  if (sum != get_checksum())
    goto FAILED;

  /* verify file names */
  first_empty_byte = super.start + super.size;
  super.setPosition(FAT_OFFSET);
  for (size_t i=0; i<exists; i++){
    toc_item_t ti;
    read_toc_item(&ti, i);

    if (OSAL_FAILED == check_name(ti.name, NVRAM_FS_MAX_FILE_NAME_LEN))
      goto FAILED;
    if ((ti.start + ti.size) >= mtd.capacity())
      goto FAILED;
    if (ti.start < first_empty_byte)
      goto FAILED;
  }

  super.close();
  return OSAL_SUCCESS;

FAILED:
  super.close();
  return OSAL_FAILED;
}
Esempio n. 13
0
HRESULT
SORAAPI
_CheckTXError(
	PSORA_RADIO pRadio,
	s_uint16 Checksum) {

	extern HRESULT _SoraRadioReadRFReg(PSORA_RADIO pRadio, s_uint32 addr, OUT s_uint32 *pValue);
	s_uint32 addr_23_CountChecksum;
	s_uint32 addr_21_CountChecksum;
	HRESULT hr;
	hr = E_TX_TRANSFER_CHECKSUM_FAIL;

	DbgPrint("TX Checksum: [0x%x], TX Count: [%d](16-bits)\n",  
		get_checksum(READ_REGISTER_ULONG((PULONG)&((pRadio->__ctrl_reg.pRadioRegs->TXCountChecksum)))),
		get_count(READ_REGISTER_ULONG((PULONG)&((pRadio->__ctrl_reg.pRadioRegs->TXCountChecksum)))));

	if (SUCCEEDED(_SoraRadioReadRFReg(pRadio,
		0x0023,
		&addr_23_CountChecksum))) {
		DbgPrint("addr 23 Checksum: [0x%x], addr 23 Count: [%d](16-bits)\n", 
			get_checksum(addr_23_CountChecksum), 
			get_count(addr_23_CountChecksum));
		if (get_checksum(addr_23_CountChecksum) != Checksum)
			hr = E_TX_TRANSFER_ADDR23_CHECKSUM_FAIL;
	}
	else
		DbgPrint("Failed to get addr 23 CountChecksum\n");

	if (SUCCEEDED(_SoraRadioReadRFReg(pRadio,
		0x0021,
		&addr_21_CountChecksum))) {
		DbgPrint("addr 21 Checksum: [0x%x], addr 21 Count: [%d](16-bits)\n", 
			get_checksum(addr_21_CountChecksum), 
			get_count(addr_21_CountChecksum));
		if (get_checksum(addr_21_CountChecksum) != Checksum)
			hr = E_TX_TRANSFER_ADDR21_CHECKSUM_FAIL;
	}
	else
		DbgPrint("Failed to get addr 21 CountChecksum\n");
	
	return hr;
}
Esempio n. 14
0
void* receive_thread(void *arg)
{
	struct receive_param rcv_para = *((struct receive_param *)arg);
	PMIFI_PACKET packet, resp;
	u8 sum;
	int len;
	const int buff_len = 1024;
	
	packet = (PMIFI_PACKET)malloc(buff_len);
	resp = (PMIFI_PACKET)malloc(buff_len);
	memset(packet, 0x0, buff_len);

	while (read_packet(rcv_para.sd, packet) != ERROR) {
		DBG_OUT("Process received packet");

		len = get_packet_len(packet);
		sum = get_checksum((u8*)packet, len - 1);
		DBG_OUT("len = %d, recv sum = 0x%02x, calc sum = 0x%02x", len, ((u8*)packet)[len - 1], sum);
		dump_packet(packet);
        if (((u8*)packet)[len - 1] != sum)
            DBG_OUT("*** check sum fail");

        if (is_client_response(packet->func) == 0) {
			handle_packet(rcv_para.sd, packet);
			len = server_build_response(packet, resp);
			DBG_OUT("build response len is %d", len);
			if (len > 0) {
				DBG_OUT("enqueue packet to queue");
				push_data(rcv_para.sd, (u8*)resp, len);
			}
			handle_packet_post(rcv_para.sd, packet);
        } else {
        	DBG_OUT("It's a response packet from client, ignored.");
        }

		memset(packet, 0x0, buff_len);
	} /* while(read_packet) */

	DBG_OUT("terminated thread 0x%lx", (unsigned long)pthread_self());

    for (len = 0; len < ARRAY_SIZE(dev_map); len++)
    {
        if (dev_map[len].sd == rcv_para.sd)
        {
            dev_map[len].valid = 0;
            break;
        }
    }
    
	free(packet);
	free(resp);
	pthread_exit((void *)0);
	return NULL;
}
Esempio n. 15
0
// used to test out the get public data events
void SimpleShell::set_temp_command( string parameters, StreamOutput* stream){
    string type= shift_parameter( parameters );
    string temp= shift_parameter( parameters );
    double t= temp.empty() ? 0.0 : strtod(temp.c_str(), NULL);
    bool ok= this->kernel->public_data->set_value( temperature_control_checksum, get_checksum(type), &t );

    if(ok) {
        stream->printf("%s temp set to: %3.1f\r\n", type.c_str(), t);
    }else{
        stream->printf("%s is not a known temperature device\r\n", type.c_str());
    }
}
Esempio n. 16
0
/*---------------------------------------------------------------------------*/
bool Shell::parse(register char *str, struct ptentry *t)
{
    struct ptentry *p;
    for (p = t; p->command_cs != 0; ++p) {
        if (get_checksum(str) == p->command_cs) {
            break;
        }
    }

    p->pfunc(str, this);

    return p->command_cs != 0;
}
Esempio n. 17
0
// When a new line is received, check if it is a command, and if it is, act upon it
void Configurator::on_console_line_received( void* argument ){
    SerialMessage new_message = *static_cast<SerialMessage*>(argument);
    string possible_command = new_message.message;

    // We don't compare to a string but to a checksum of that string, this saves some space in flash memory
    uint16_t check_sum = get_checksum( possible_command.substr(0,possible_command.find_first_of(" \r\n")) );  // todo: put this method somewhere more convenient

    // Act depending on command
    switch( check_sum ){
        case config_get_command_checksum: this->config_get_command(  get_arguments(possible_command), new_message.stream ); break;
        case config_set_command_checksum: this->config_set_command(  get_arguments(possible_command), new_message.stream ); break;
        case config_load_command_checksum: this->config_load_command(  get_arguments(possible_command), new_message.stream ); break;
    }
}
Esempio n. 18
0
int server_build_response(PMIFI_PACKET packet, PMIFI_PACKET resp)
{
	int datalen = 0, packetlen = 0;
	u8 sum;
	u16 func = packet->func;

	memcpy(resp, packet, sizeof(*packet));
	resp->func = 0x8001;  // little-endian: 0x0180

	switch (func)	{
	case MIFI_CLI_LOGIN:
	case MIFI_CLI_ALIVE:
	case MIFI_CLI_LOGOUT:
		datalen = 100;
		resp->datalen = htons(datalen);
		memset(resp->data, 0xcc, datalen);
		resp->data[0] = (u8)(func);
		resp->data[1] = (u8)(func >> 8);
		resp->data[2] = 'O';
		resp->data[3] = 'K';
		resp->data[98] = 'K';
		resp->data[99] = 'O';
		break;

	case MIFI_USR_CHECK:
        {
            char *purl = "http://news.baidu.com";
            int url_len = strlen(purl);
            datalen = url_len + 5;
            resp->datalen = htons(datalen);
            resp->data[0] = 0x00;
            resp->data[1] = 0x07;
            resp->data[2] = 0x00;
            resp->data[3] = (u8)(url_len >> 8);
            resp->data[4] = (u8)(url_len);
            strcpy((char *)resp->data + 5, purl);
        }
        break;

	default:
		return -1;
	}

	packetlen =  sizeof(MIFI_PACKET) + datalen;
	sum = get_checksum((u8 *)resp, packetlen);
	*(((u8 *)resp) + packetlen) = sum;
	return packetlen + 1;
}
Esempio n. 19
0
// When a new line is received, check if it is a command, and if it is, act upon it
void SimpleShell::on_console_line_received( void* argument ){
    SerialMessage new_message = *static_cast<SerialMessage*>(argument);
    string possible_command = new_message.message;

    // We don't compare to a string but to a checksum of that string, this saves some space in flash memory
    unsigned short check_sum = get_checksum( possible_command.substr(0,possible_command.find_first_of(" \r\n")) );  // todo: put this method somewhere more convenient

    // Act depending on command
    switch( check_sum ){
        case ls_command_checksum      : this->ls_command(  get_arguments(possible_command), new_message.stream ); break;
        case cd_command_checksum      : this->cd_command(  get_arguments(possible_command), new_message.stream ); break;
        case pwd_command_checksum     : this->pwd_command( get_arguments(possible_command), new_message.stream ); break;
        case cat_command_checksum     : this->cat_command( get_arguments(possible_command), new_message.stream ); break;
        case play_command_checksum    : this->play_command(get_arguments(possible_command), new_message.stream ); break; 
        case reset_command_checksum   : this->reset_command(get_arguments(possible_command),new_message.stream ); break;
    }
}
Esempio n. 20
0
// When a new line is received, check if it is a command, and if it is, act upon it
void SimpleShell::on_console_line_received( void *argument )
{
    SerialMessage new_message = *static_cast<SerialMessage *>(argument);

    // ignore comments
    if (new_message.message[0] == ';') return;

    string possible_command = new_message.message;

    //new_message.stream->printf("Received %s\r\n", possible_command.c_str());

    // We don't compare to a string but to a checksum of that string, this saves some space in flash memory
    unsigned short check_sum = get_checksum( possible_command.substr(0, possible_command.find_first_of(" \r\n")) ); // todo: put this method somewhere more convenient

    // find command and execute it
    parse_command(check_sum, get_arguments(possible_command), new_message.stream);
}
Esempio n. 21
0
t_header	*create_header(char *arg)
{
  t_header	*head;

  if ((head = malloc(sizeof(t_header))) == NULL)
    return (NULL);
  memset(head, '\0', sizeof(t_header));
  if (sprintf(head->chksum, "        ") < 0)
    return (NULL);
  if (infos_header(head, arg) == 1)
    return (NULL);
  head->mode[1] = '0';
  head->mode[2] = '0';
  head->chksum[7] = ' ';
  if (sprintf(head->chksum, "%0*o", 6, get_checksum(head)) < 0)
    return (NULL);
  return (head);
}
Esempio n. 22
0
/**
 * Returns TRUE if the checksum was changed for associated
 * path and send an alert warning.
 * Returns FALSE if the checksum is the same or not defined
 * for this service.
 */
static int check_checksum(Service_T s, char *report) {

  ASSERT(s);

  if(!s->checksum)
    return FALSE;

  if( !check_hash(s->path, s->checksum->hash, s->checksum->type) ) {
    snprintf(report, STRLEN, "checksum test failed for %s", s->path);
    /* Set the old checksum to the new value so we do not report this
     * more than once per change */
    FREE(s->checksum->hash);
    s->checksum->hash= get_checksum(s->path, s->checksum->type);
    return TRUE;
  }
  
  DEBUG("'%s' has valid checksums\n", s->name);
  
  return FALSE;

}
Esempio n. 23
0
// Write the specified setting to the specified ConfigSource
void Configurator::config_set_command( string parameters, StreamOutput* stream ){
    string source = shift_parameter(parameters);
    string setting = shift_parameter(parameters);
    string value = shift_parameter(parameters);
    if (value == "") {
        value = setting;
        setting = source;
        source = "";
        this->kernel->config->set_string(setting, value);
        stream->printf( "live: %s has been set to %s\r\n", setting.c_str(), value.c_str() );
    } else {
        uint16_t source_checksum = get_checksum(source);
        for(int i=0; i < this->kernel->config->config_sources.size(); i++){
            if( this->kernel->config->config_sources[i]->is_named(source_checksum) ){
                this->kernel->config->config_sources[i]->write(setting, value);
                stream->printf( "%s: %s has been set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() );
                break;
            }
        }
    }
}
Esempio n. 24
0
static void check_value_dupl(struct xattr_list *xattr)
{
	struct xattr_list *entry;

	if(xattr->vsize < XATTR_VALUE_OOL_SIZE)
		return;

	/* Check if this is a duplicate of an existing value */
	xattr->vchecksum = get_checksum(xattr->value, xattr->vsize, 0);
	for(entry = dupl[xattr->vchecksum]; entry; entry = entry->vnext) {
		if(entry->vsize != xattr->vsize)
			continue;
		
		if(memcmp(entry->value, xattr->value, xattr->vsize) == 0)
			break;
	}

	if(entry == NULL) {
		/*
		 * No duplicate exists, add to hash table, and mark as
		 * requiring writing
		 */
		xattr->vnext = dupl[xattr->vchecksum];
		dupl[xattr->vchecksum] = xattr;
		xattr->ool_value = SQUASHFS_INVALID_BLK;
	} else {
		/*
		 * Duplicate exists, make type XATTR_VALUE_OOL, and
		 * remember where the duplicate is
		 */
		xattr->type |= XATTR_VALUE_OOL;
		xattr->ool_value = entry->ool_value;
		/* on appending don't free duplicate values because the
		 * duplicate value already points to the non-duplicate value */
		if(xattr->value != entry->value) {
			free(xattr->value);
			xattr->value = entry->value;
		}
	}
}
Esempio n. 25
0
int handle_packet_post(int sd, PMIFI_PACKET packet)
{
    int /*n,*/ datalen, packetlen;
    u16 func = packet->func;
    PMIFI_PACKET p;
    u8 sum;
    
    switch (func) {
    case MIFI_USR_CHECK:
        {
            //char *url = "http://baike.baidu.com/";
            struct PACK_ALIGN(1) {
                u16 bytes;
                u32 time;
            } allow;

            datalen = sizeof(macadr_t) + sizeof(allow);
            packetlen =  sizeof(MIFI_PACKET ) + datalen;
            p = (PMIFI_PACKET)malloc(packetlen + 1);

            memcpy(p, packet, sizeof(MIFI_PACKET));

            p->func = SERV_SET_PERMIT;
            p->sn_packet = htonl(get_packet_sn());
            p->datalen = htons(datalen);
            memcpy(p->data, packet->data, sizeof(macadr_t));

            allow.bytes = htons(50); // 50M
            allow.time = htons(3600); // 1 hours
            memcpy(p->data + sizeof(macadr_t), &allow, sizeof(allow));

            sum = get_checksum((u8 *)p, packetlen);
            *(((u8 *)p) + packetlen) = sum;
            push_data(sd, (u8 *)p, packetlen + 1);
        }
        break;
    }
    return 0;
}
Esempio n. 26
0
static void
test_get_checksum_icmp_packet() {
  ipv4_header_t ipv4_header;

  // Create a test packet.
  memset( &ipv4_header, 0, sizeof( ipv4_header ) );
  ipv4_header.version = 4;
  ipv4_header.ihl = 5;
  ipv4_header.tos = 0;
  ipv4_header.tot_len = htons( 0x0054 );
  ipv4_header.id = htons( 0xaec3 );
  ipv4_header.frag_off = htons( 0 );
  ipv4_header.ttl = 0x40;
  ipv4_header.protocol = 0x01;
  ipv4_header.csum = 0;
  ipv4_header.saddr = htonl( 0xc0a8642b );
  ipv4_header.daddr = htonl( 0xc0a8642c );

  uint16_t checksum = get_checksum( ( uint16_t * ) &ipv4_header,
                                    sizeof( ipv4_header ) );
  assert_int_equal( checksum, 0x3d82 );
}
Esempio n. 27
0
static void
test_get_checksum_udp_packet() {
  ipv4_header_t ipv4_header;

  // Create a test packet.
  memset( &ipv4_header, 0, sizeof( ipv4_header ) );
  ipv4_header.version = 4;
  ipv4_header.ihl = 5;
  ipv4_header.tos = 0;
  ipv4_header.tot_len = htons( 0x004c );
  ipv4_header.id = htons( 0x48d8 );
  ipv4_header.frag_off = htons( 0 );
  ipv4_header.ttl = 0x80;
  ipv4_header.protocol = 0x11;
  ipv4_header.csum = 0;
  ipv4_header.saddr = htonl( 0x0a3835af );
  ipv4_header.daddr = htonl( 0x0a3837ff );

  uint16_t checksum = get_checksum( ( uint16_t * ) &ipv4_header,
                                    sizeof( ipv4_header ) );
  assert_int_equal( checksum, 0xab6f );
}
Esempio n. 28
0
/* Send IDENT packet */
void network_packet ( network_type *n, 
                      unsigned char packet_type, 
                      unsigned char *data,
                      unsigned int data_length )
{
    unsigned char buffer[1000];

    unsigned int length = TX_DATA_OFS + data_length;

    unsigned int i = 0;
    
   
    buffer[i++] = length >> 8;
    buffer[i++] = length &  0xff;

    buffer[i++] = n->node_id >> 8;
    buffer[i++] = n->node_id &  0xff;

    buffer[i++] = 0;//node_id >> 8;
    buffer[i++] = 0;//node_id &  0xff;


    buffer[i++] = packet_type;
    
    buffer[i++] = 0;  // No checksum for now
    

    int j = 0;

    // Copy payload
    for (j= 0; j < data_length; j++)
        buffer[i++] = data[j];
        
    buffer[TX_DATA_OFS-1] = get_checksum(buffer, length);

    network_send(n, buffer, length);

}
Esempio n. 29
0
static buffer *
setup_dummy_ether_ipv4_packet() {
  buffer *ipv4_buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) + sizeof( ipv4_header_t ) + ipv4_padding_size, ETH_ETHTYPE_IPV4 );

  ipv4_header_t *ipv4 = packet_info( ipv4_buffer )->l3_data.ipv4;
  ipv4->version = IPVERSION;
  ipv4->ihl = sizeof( ipv4_header_t ) / 4;
  ipv4->tot_len = htons( sizeof( ipv4_header_t ) );
  ipv4->ttl = 0;
  ipv4->check = 0;
  ipv4->protocol = IPPROTO_UDP;
  ipv4->saddr = htonl( 0xC0A80067 );
  ipv4->daddr = htonl( 0xC0A80036 );
  ipv4->frag_off = htons( 0 );
  ipv4->check = get_checksum( ( uint16_t * ) packet_info( ipv4_buffer )->l3_data.ipv4, sizeof( ipv4_header_t ) );

  free( ipv4_buffer->user_data );
  ipv4_buffer->user_data = NULL;

  remove_front_buffer( ipv4_buffer, ETH_PREPADLEN );

  return ipv4_buffer;
}
Esempio n. 30
0
// Output a ConfigValue from the specified ConfigSource to the stream
void Configurator::config_get_command( string parameters, StreamOutput* stream ){
    string source = shift_parameter(parameters);
    string setting = shift_parameter(parameters);
    if (setting == "") { // output live setting
        setting = source;
        source = "";
        vector<uint16_t> setting_checksums = get_checksums( setting );
        ConfigValue* cv = this->kernel->config->value(setting_checksums);
        string value = "";
        if(cv->found){ value = cv->as_string(); }
        stream->printf( "live: %s is set to %s\r\n", setting.c_str(), value.c_str() );
    } else { // output setting from specified source
        uint16_t source_checksum = get_checksum( source );
        vector<uint16_t> setting_checksums = get_checksums( setting );
        for(int i=0; i < this->kernel->config->config_sources.size(); i++){
            if( this->kernel->config->config_sources[i]->is_named(source_checksum) ){
                string value = this->kernel->config->config_sources[i]->read(setting_checksums);
                stream->printf( "%s: %s is set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() );
                break;
            }
        }
    }
}