Ejemplo n.º 1
0
static int ois_convert_to_iso88591(char *raw, int len)
{
    /* a best effort 1-to-1 conversion according to ois appendix a */

    static const char gsm_to_iso88591[] = {
	'@', 0xa3,'$', 0xa5,0xe8,0xe9,0xf9,0xec, /* 0x00 - 0x07 */
	0xf2,0xc7,'\n',0xd8,0xf8,'\r',0xc5,0xe5, /* 0x08 - 0x0f */
	'D', ' ', 'F', 'G', 'L', 'W', 'P', 'Y',  /* 0x10 - 0x17, poor! */
	'Y', 'S', 'X', ' ', 0xc6,0xe6,'b', 0xc9, /* 0x18 - 0x1f, poor! */
	' ', '!', '"', '#', 0xa4, '%', '&', '\'',/* 0x20 - 0x27 */
	'(', ')', '*', '+', ',', '-', '.', '/',  /* 0x28 - 0x2f */
	'0', '1', '2', '3', '4', '5', '6', '7',  /* 0x30 - 0x37 */
	'8', '9', ':', ';', '<', '=', '>', '?',  /* 0x38 - 0x3f */
	0xa1,'A', 'B', 'C', 'D', 'E', 'F', 'G',  /* 0x40 - 0x47 */
	'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',  /* 0x48 - 0x4f */
	'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',  /* 0x50 - 0x57 */
	'X', 'Y', 'Z', 0xc4,0xd6,0xd1,0xdc,0xa7, /* 0x58 - 0x5f */
	0xbf,'a', 'b', 'c', 'd', 'e', 'f', 'g',  /* 0x60 - 0x67 */
	'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',  /* 0x68 - 0x6f */
	'p', 'q', 'r', 's', 't', 'u', 'v', 'w',  /* 0x70 - 0x77 */
	'x', 'y', 'z', 0xe4,0xf6,0xf1,0xfc,0xe0  /* 0x78 - 0x7f */
    };

    int i;

    SAY2(3, "ois_convert_to_iso88591 len=%d", len);

    for (i = 0; i < len; ++i) {
	raw[i] = gsm_to_iso88591[raw[i] & 0x7f];
    }

    SAY2(5, "ois_convert_to_iso88591 gave [%s]", ois_debug_str(raw, i));
    return i;
}
Ejemplo n.º 2
0
static int ois_open_receiver(SMSCenter *smsc)
{
    struct sockaddr_in addr;
    int addrlen;
    Octstr *os;

    SAY(2, "ois_open_receiver");

    /* the listening socket should be non-blocking... */

    addrlen = sizeof(addr);
    smsc->socket = accept(smsc->ois_listening_socket,
			  (struct sockaddr *)&addr, (socklen_t *)&addrlen);
    if (smsc->socket == -1) {
	if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
	    /* || errno == ECONNABORTED || errno == EPROTO) -Kalle 6.7 */
	{
	    return 0;
	} else {
	    error(errno, "ois_open_receiver: accept failed");
	    smsc->ois_flags |= OIS_FLAG_ERROR;
	    return -1;
	}
    }

    SAY2(2, "ois_open_receiver fd=%d", smsc->socket);
    os = gw_netaddr_to_octstr(AF_INET, &addr.sin_addr);
    debug("bb.sms.ois", 0, "connection from host %s port %hu",
	  octstr_get_cstr(os), ntohs(addr.sin_port));
    octstr_destroy(os);
    time(&smsc->ois_alive);
    return 0;
}
Ejemplo n.º 3
0
static int ois_open_listener(SMSCenter *smsc)
{
    SAY(2, "ois_open_listener");

    smsc->ois_listening_socket = make_server_socket(smsc->receive_port, 
		    NULL);
	/* XXX add interface_name if required */
    if (smsc->ois_listening_socket < 0) {
	goto error;
    }
    if (socket_set_blocking(smsc->ois_listening_socket, 0) < 0) {
	ois_close(smsc);
	goto error;
    }
    smsc->ois_flags &= ~OIS_FLAG_ERROR;
    smsc->ois_flags &= ~OIS_FLAG_NOBANNER;
    smsc->ois_alive2 = time(&smsc->ois_alive);

    SAY2(2, "ois_open_listener fd=%d", smsc->ois_listening_socket);
    return 0;

 error:
    error(0, "ois_open_listener: failed to open listening socket");
    return -1;
}
Ejemplo n.º 4
0
static int ois_extract_line_from_buffer(char *str, SMSCenter *smsc)
{
    int len;

    SAY2(3, "ois_extract_line_from_buffer buflen=%ld", (long)smsc->buflen);

    str[0] = '\0';

    for (len = 0; (size_t) len < smsc->buflen && smsc->buffer[len] != '\n'; 
         ++len) ;

    if ((size_t) len >= smsc->buflen) {
	return 0;
    } else {
	++len;
    }

    /* the buffer contains a line */

    memcpy(str, smsc->buffer, len);
    str[len] = '\0';
    smscenter_remove_from_buffer(smsc, len); /* just the line */

    return len;
}
Ejemplo n.º 5
0
static int ois_extract_msg_from_buffer(char *str, SMSCenter *smsc)
{
    int len;
    int count;

    SAY2(8, "ois_extract_msg_from_buffer buflen=%ld", (long)smsc->buflen);

    str[0] = '\0';

    if (smsc->buflen < 7) {             /* 7 = 6 + 1 */
	return 0;              /* we don't have a message yet */
    }

    if (strchr("SRDATECQLMPOVsrdatecqlmpov", smsc->buffer[0]) == NULL
	|| (smsc->buffer[1] & 0xf0) != 0x50) {

	goto error;
    }

    /* a valid message type, find the end of the message */

    count = smsc->buffer[1] & 0x0f;
    for (len = 0; (size_t) len < smsc->buflen; ++len) {
	if (smsc->buffer[len] == EOL) {
	    if (--count < 0) {
		++len;
		break;
	    }
	}
    }

    if (count >= 0) {          /* we don't have all the pieces */
	if (len < BUFLEN) {
	    return 0;          /* ...but maybe later */
	}
	goto error;
    }

    /* the buffer contains a promising message candidate */

    memcpy(str, smsc->buffer, len);
    str[len] = '\0';
    smscenter_remove_from_buffer(smsc, len); /* just the message */

    return len;

 error:
    for (len = 0; (size_t) len < smsc->buflen && smsc->buffer[len] != EOL; 
         ++len) ;
    if (len > BUFLEN) len = BUFLEN;

    memcpy(str, smsc->buffer, len);
    str[len] = '\0';
    smscenter_remove_from_buffer(smsc, smsc->buflen); /* everything */

    return -len;
}
Ejemplo n.º 6
0
static int ois_expand_gsm7(char *raw8, const char *raw7, int len)
{
    int i;
    char bits[8*(BUFLEN+1)];

    SAY2(3, "ois_expand_gsm7 len=%d", len);

    /* yeah, there are also better algorithms, but... */
    /* well, at least this is fairly portable and ok for small messages... */

    ois_expand_gsm7_to_bits(bits, raw7, len);
    for (i = 0; i < len; ++i) {
	raw8[i] = ois_expand_gsm7_from_bits(bits, i);
    }

    SAY2(5, "ois_expand_gsm7 gave [%s]", ois_debug_str(raw8, i));
    return i;
}
Ejemplo n.º 7
0
static void ois_disconnect(SMSCenter *smsc)
{
    SAY2(2, "ois_disconnect fd=%d", smsc->socket);

    if (smsc->socket != -1) {
	if (close(smsc->socket) == -1) {
	    warning(errno, "ois_disconnect: close failed...");
	}
	smsc->socket = -1;
    }
    return;
}
Ejemplo n.º 8
0
static int ois_convert_from_ia5(char *raw, const char *str)
{
    int j;
    int i;
    int ch;

    SAY(3, "ois_convert_from_ia5");

    for (j = i = 0; ; ++i) {
	ch = str[i] & 0xff;
	if (ch < 0x20 || 0x7f <= ch) {
	    break;
	} else if (ch == 0x5c) {
	    ch = str[++i] & 0xff;
	    if (ch == 0x5c || ch == 0x5e || ch == 0x60 || ch == 0x7e) {
		raw[j++] = (char) ch;
	    } else {
		break;
	    }
	} else if (ch == 0x5e) {
	    ch = str[++i] & 0xff;
	    if (0x40 <= ch && ch < 0x60) {
		raw[j++] = (char) ch - 0x40;
	    } else if (ch == 0x7e) {
		raw[j++] = (char) 0x7f;
	    } else {
		break;
	    }
	} else if (ch == 0x60) {
	    ch = str[++i] & 0xff;
	    if (0x20 <= ch && ch < 0x7f) {
		raw[j++] = (char) ch + 0x80;
	    } else {
		break;
	    }
	} else if (ch == 0x7e) {
	    ch = str[++i] & 0xff;
	    if (0x40 <= ch && ch < 0x60) {
		raw[j++] = (char) ch + 0x40;
	    } else if (ch == 0x7e) {
		raw[j++] = (char) 0xff;
	    } else {
		break;
	    }
	} else { /* 0x20 <= ch && ch < 0x7f */
	    raw[j++] = (char) ch;
	}
    }

    SAY2(5, "ois_convert_from_ia5 gave [%s]", ois_debug_str(raw, j));
    return j;
}
Ejemplo n.º 9
0
static int ois_convert_to_ia5(char *str, const char *raw, int len)
{
    int j;
    int i;
    int ch;

    SAY2(3, "ois_convert_to_ia5 len=%d", len);

    for (j = i = 0; i < len; ++i) {
	ch = raw[i] & 0xff;
	if (ch == 0x5c || ch == 0x5e || ch == 0x60 || ch == 0x7e) {
  	    str[j++] = (char) 0x5c;
  	    str[j++] = (char) ch;
	} else if (0x20 <= ch && ch < 0x7f) {
	    str[j++] = (char) ch;
	} else if (0x00 <= ch && ch < 0x20) {
	    str[j++] = (char) 0x5e;
	    str[j++] = (char) ch + 0x40;
	} else if (0xa0 <= ch && ch < 0xff) {
	    str[j++] = (char) 0x60;
	    str[j++] = (char) ch - 0x80;
	} else if (0x80 <= ch && ch < 0xa0) {
	    str[j++] = (char) 0x7e;
	    str[j++] = (char) ch - 0x40;
	} else if (ch == 0x7f) {
	    str[j++] = (char) 0x5e;
	    str[j++] = (char) 0x7e;
	} else { /* ch == 0xff */
	    str[j++] = (char) 0x7e;
	    str[j++] = (char) 0x7e;
	}
    }

    str[j] = '\0';
    SAY2(5, "ois_convert_to_ia5 gave [%s]", ois_debug_str(str, j));
    return j;
}
Ejemplo n.º 10
0
static char ois_expand_gsm7_from_bits(const char *bits, int pos)
{
    int i;
    char ch;

    SAY2(8, "ois_expand_gsm7_from_bits pos=%d", pos);

    pos *= 7; /* septet position in bits */
    ch = '\0';
    for (i = 6; i >= 0; --i) {
	ch <<= 1;
	ch |= bits[pos+i];
    }

    return ch;
}
Ejemplo n.º 11
0
void handle_clock_interrupt(){
    CLOCK_TIME quantum_time_used = clock - process_table[current_pid].quantum_start_time;
  /* Check if the current process has used up its QUANTUM */
    print_process_table();
  if(current_pid ==-1){
    run_next_process();
    return;
  }
  if (quantum_time_used >= QUANTUM){
    SAY2("PID %d has run for %d. That's enough. \n",current_pid, quantum_time_used);
    update_CPU_time_used(current_pid);
    process_table[current_pid].state = READY;
    process_table[current_pid].quantum_start_time = 0;
    queue_ready_process(current_pid);
    run_next_process();
  }
}
Ejemplo n.º 12
0
static void ois_disconnect_all(SMSCenter *smsc)
{
    SAY2(2, "ois_disconnect_all fd=%d", smsc->ois_listening_socket);

    ois_swap_buffering(smsc);
    SAY(4, "ois_disconnect_all: ois_disconnect");
    ois_disconnect(smsc); /* smsc->socket */
    ois_swap_buffering(smsc);
    SAY(4, "ois_disconnect_all: ois_disconnect");
    ois_disconnect(smsc); /* smsc->socket */

    if (smsc->ois_listening_socket != -1) {
	if (close(smsc->ois_listening_socket) == -1) {
	    warning(errno, "ois_disconnect_all: close failed...");
	}
	smsc->ois_listening_socket = -1;
    }
    return;
}
Ejemplo n.º 13
0
void print_entry(int i, int j, PT_ENTRY* table_L2){
  if (get_present_bit(table_L2[j]))
    SAY2("[%d]-%x\n",j,table_L2[j]);
}
Ejemplo n.º 14
0
static int ois_open_sender(SMSCenter *smsc)
{
    int ret;
    char buffer[BUFLEN+1];
    time_t now;
    time_t beginning;
    
    SAY(2, "ois_open_sender");
    debug("bb.sms.ois", 0, "connecting to host %s port %d",
	  smsc->hostname, smsc->port);

    time(&beginning);
    smsc->socket = tcpip_connect_to_server(smsc->hostname, smsc->port,
		    NULL);
	/* XXX add interface_name if required */
    if (smsc->socket < 0) {
	return -1;
    } else {
	smsc->buflen = 0;
	time(&smsc->ois_alive);
	smsc->ois_ack_debt = 0;
    }

    SAY2(2, "ois_open_sender fd=%d", smsc->socket);
    if (smsc->ois_flags & OIS_FLAG_NOBANNER) {
	return 0;
    }

    buffer[0] = '\0';
    for (time(&now); (now - beginning) < OIS_OPEN_WAITTIME; time(&now)) {
	ret = ois_read_into_buffer(smsc, OIS_WAITTIME);
	if (ret < 0) {
	    goto error;
	}

	if (smsc->buflen == 0) {
	    /* assume that the router is in the quiet mode */
	    /* there will be no banners */
	    smsc->ois_flags |= OIS_FLAG_NOBANNER;
	    debug("bb.sms.ois", 0, "assuming that %s:%d is in the quiet mode",
		  smsc->hostname, smsc->port);
	    return 0;
	}
	ret = ois_extract_line_from_buffer(buffer, smsc);
	if (ret > 0) {
	    if (strncmp(buffer, "Trying", 6) == 0 &&
		strstr(buffer, "...Open\r\n") != NULL) {
		time(&smsc->ois_alive);
		return 0;
	    } else {
		break;
	    }
	}
    }

 error:
    SAY(4, "ois_open_sender: ois_disconnect in error");
    ois_disconnect(smsc);
    error(0, "ois_open_sender: failed to connect [%s%s]",
	  buffer, ois_debug_str(smsc->buffer, smsc->buflen));
    return -1;
}
Ejemplo n.º 15
0
void handle_disk_read() {
  SAY2("PID %d handling disk read of size: %d\n",R2,current_pid);
  disk_read_req(current_pid, R2);
  block_current_process();
  run_next_process();
}