Exemplo n.º 1
0
void
ropa_break_client (uint32_t host, uint16_t port)
{
    struct ropa_client *c;

    c = client_query (host, port);
    if (c == NULL) {
	/* XXX warn */
	return;
    }

    break_client (c, TRUE);
}
Exemplo n.º 2
0
int
ropa_drop_callbacks (uint32_t addr, uint16_t port,
		     const AFSCBFids *a_cbfids_p, const AFSCBs *a_cbs_p)
{
    struct ropa_client *c;
    struct ropa_cb cbkey, *cb;
    struct ropa_ccpair cckey, *cc;
    int i; 
    
    debug_print_callbacks();

    if (a_cbfids_p->len > AFSCBMAX)
	return EINVAL;

    c = client_query (addr, port);
    if (c == NULL) {
	mlog_log (MDEBROPA, "ropa_drop_callbacks: didn't find client %x/%d",
		  addr, port);
	return 0;
    }

    for (i = 0; i < a_cbfids_p->len; i++) {
	cbkey.fid = a_cbfids_p->val[i];
	
	cb = hashtabsearch (ht_callbacks, &cbkey);
	if (cb != NULL) {
	    cckey.client = c;
	    cckey.cb = cb;
	    
	    cc = hashtabsearch (ht_ccpairs, &cckey);
	    if (cc != NULL) {
		mlog_log (MDEBROPA, "ropa_drop: dropping %x.%x.%x:%x/%d",
			  cb->fid.Volume, cb->fid.Vnode, cb->fid.Unique, 
			  addr, port);
		break_ccpair (cc, FALSE);
	    }
	}
    }
    
    debug_print_callbacks();

    return 0;
}
Exemplo n.º 3
0
int
ropa_getcallback (uint32_t host, uint16_t port, const struct AFSFid *fid,
		  AFSCallBack *callback, int32_t voltype)
{
    struct ropa_client *c;
    struct ropa_cb cbkey, *cb;
    struct ropa_ccpair *cc ;
    struct AFSFid callback_fid;

    debug_print_callbacks();

    c = client_query (host, port);
    if (c == NULL) {
	mlog_log (MDEBROPA, "ropa_getcallback: didn't find client %x/%d",
		  host, port);
	update_callback_time (DEFAULT_TIMEOUT, callback, CBSHARED);
	return 0;
    }

    /*
     * At this point the client should be firmly set
     * in the ropa client database.
     */

#if 0
    if (c->have_outstanding_callbacks)
	break_outstanding_callbacks (c);
#endif

    if (voltype == RWVOL) {
	callback_fid = *fid;
    } else {
	callback_fid.Volume = fid->Volume;
	callback_fid.Vnode = 0;
	callback_fid.Unique = 0;
    }

    cbkey.fid = callback_fid;

    cb = hashtabsearch (ht_callbacks, &cbkey);
    if (cb == NULL) {
	cb = listdeltail (lru_callback);
	DIAGNOSTIC_CHECK_CALLBACK(cb);
	cb->li = NULL;
	if (callback_inuse_p (cb)) {
	    break_callback (cb, NULL, FALSE);
	    callback_ref(cb);
	} else {
	    callback_ref(cb);
	    cb->li = listaddhead (lru_callback, cb);
	}
	cb->fid = callback_fid;
	hashtabadd (ht_callbacks, cb);

	mlog_log (MDEBROPA, "ropa_getcallback: added callback %x.%x.%x:%x",
		  callback_fid.Volume, callback_fid.Vnode,
		  callback_fid.Unique, host);
    } else {
	mlog_log (MDEBROPA, "ropa_getcallback: found callback %x.%x.%x:%x",
		  callback_fid.Volume, callback_fid.Vnode,
		  callback_fid.Unique, host);
	callback_ref(cb);
    }

    cc = add_client (cb, c);

    callback_deref (cb);

    update_callback (cc, callback, CBSHARED);

    debug_print_callbacks();

    return 0;
}
Exemplo n.º 4
0
/**
 * @brief Displays shell and parses input from user.
 *
 * Only allows integer input.
 * Call a function based on user selection (1-6).
 * If connected to a server, it disconnects before exiting.
 * @param r A pointer to a record structure.
 * @return Returns 0 on success, -1 otherwise.
 */
int command_parser()
{
    
    printf("\n\n------------------------------------------\n"
           "\t1) Connect\n"
           "\t2) Authenticate\n"
           "\t3) Get\n"
           "\t4) Set\n"
           "\t5) Query\n"
           "\t6) Disconnect\n"
           "\t7) Exit\n"
           "------------------------------------------\n\n\n");
    
    int option, status;
    struct storage_record r;
    
    bool read_success = false;
    while(read_success == false)
    {
        printf("Please enter your selection: ");
        char *l = fgets(input_buffer, sizeof input_buffer, stdin);
        if(l != input_buffer || (sscanf(input_buffer, "%d %s", &option, trash) != 1) || option > 7 || option < 1)
            printf("Invalid selection. Please enter a valid option number (1-6).\n");
        else
            read_success = true;
    }
    
    switch (option)
    {
        case 1: // Connect to server
            status = client_connect();
            break;
            
        case 2: // Authenticate the client.
            status = client_auth();
            break;
            
        case 3: // Issue storage_get
            client_get(&r);
            n_gets++;
            break;
            
        case 4: // Issue storage_set
            client_set(&r);
            n_sets++;
            break;
            
        case 5: //Issue client_query
            client_query();
            break;
            
        case 6: // Disconnect from server
            status = client_disconnect();
            break;
            
        case 7: //Exit
            if (connected)
                status = client_disconnect();
            status = -1; // To stop main loop
            printf("Goodbye!\n");
            break;
            
        default:
            status = -1;
            printf("Invalid selection.\n");
            break;
    }
    
    return status;
}
Exemplo n.º 5
0
void
client_init(void)
{
	struct sockaddr_l2cap sa;
	channel_t *chan;
	socklen_t len;
	int fd, n;
	uint16_t mru, mtu;

	if (bdaddr_any(&remote_bdaddr))
		return;

	if (service_name)
		client_query();

	fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP);
	if (fd == -1) {
		log_err("Could not open L2CAP socket: %m");
		exit(EXIT_FAILURE);
	}

	memset(&sa, 0, sizeof(sa));
	sa.l2cap_family = AF_BLUETOOTH;
	sa.l2cap_len = sizeof(sa);
	sa.l2cap_bdaddr_type = BDADDR_BREDR;
	sa.l2cap_cid = 0;
	 
	bdaddr_copy(&sa.l2cap_bdaddr, &local_bdaddr);
	if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
		log_err("Could not bind client socket: %m");
		exit(EXIT_FAILURE);
	}

	mru = BNEP_MTU_MIN;
	if (setsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, sizeof(mru)) == -1) {
		log_err("Could not set L2CAP IMTU (%d): %m", mru);
		exit(EXIT_FAILURE);
	}

	log_info("Opening connection to service 0x%4.4x at %s",
	    service_class, bt_ntoa(&remote_bdaddr, NULL));

	sa.l2cap_psm = htole16(l2cap_psm);
	bdaddr_copy(&sa.l2cap_bdaddr, &remote_bdaddr);
	if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
		log_err("Could not connect: %m");
		exit(EXIT_FAILURE);
	}

	len = sizeof(mru);
	if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, &len) == -1) {
		log_err("Could not get IMTU: %m");
		exit(EXIT_FAILURE);
	}
	if (mru < BNEP_MTU_MIN) {
		log_err("L2CAP IMTU too small (%d)", mru);
		exit(EXIT_FAILURE);
	}

	len = sizeof(n);
	if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) {
		log_err("Could not read SO_RCVBUF");
		exit(EXIT_FAILURE);
	}
	if (n < (mru * 10)) {
		n = mru * 10;
		if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
			log_info("Could not increase SO_RCVBUF (from %d)", n);
	}

	len = sizeof(mtu);
	if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) {
		log_err("Could not get L2CAP OMTU: %m");
		exit(EXIT_FAILURE);
	}
	if (mtu < BNEP_MTU_MIN) {
		log_err("L2CAP OMTU too small (%d)", mtu);
		exit(EXIT_FAILURE);
	}

	len = sizeof(n);
	if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, &len) == -1) {
		log_err("Could not get socket send buffer size: %m");
		close(fd);
		return;
	}
	if (n < (mtu * 2)) {
		n = mtu * 2;
		if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) {
			log_err("Could not set socket send buffer size (%d): %m", n);
			close(fd);
			return;
		}
	}
	n = mtu;
	if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) {
		log_err("Could not set socket low water mark (%d): %m", n);
		close(fd);
		return;
	}

	chan = channel_alloc();
	if (chan == NULL)
		exit(EXIT_FAILURE);

	chan->send = bnep_send;
	chan->recv = bnep_recv;
	chan->mru = mru;
	chan->mtu = mtu;
	b2eaddr(chan->raddr, &remote_bdaddr);
	b2eaddr(chan->laddr, &local_bdaddr);
	chan->state = CHANNEL_WAIT_CONNECT_RSP;
	channel_timeout(chan, 10);
	if (!channel_open(chan, fd))
		exit(EXIT_FAILURE);

	bnep_send_control(chan, BNEP_SETUP_CONNECTION_REQUEST,
	    2, service_class, SDP_SERVICE_CLASS_PANU);
}