Пример #1
0
static void exchange_mtu_cb(guint8 status, const guint8 *pdu, guint16 plen,
							gpointer user_data)
{
	uint16_t mtu;

	if (status != 0) {
		resp_error(err_COMM_ERR); // Todo: status
		return;
	}

	if (!dec_mtu_resp(pdu, plen, &mtu)) {
		resp_error(err_PROTO_ERR);
		return;
	}

	mtu = MIN(mtu, opt_mtu);
	/* Set new value for MTU in client */
	if (g_attrib_set_mtu(attrib, mtu))
        {
                opt_mtu = mtu;
		cmd_status(0, NULL);
        }
	else
        {
		printf("# Error exchanging MTU\n");
		resp_error(err_COMM_ERR);
        }
}
Пример #2
0
void exchange_mtu_cb(guint8 status, const guint8 *pdu, guint16 plen,
                     gpointer user_data)
{
  uint16_t mtu;
  printf_dbg("[CB] IN exchange_mtu_cb\n");

  if (status) {
    cb_ret_val = BL_REQUEST_FAIL_ERROR;
    sprintf(cb_ret_msg, "MTU exchange callback: Failure: %s\n",
            att_ecode2str(status));
    goto error;
  }

  if (!dec_mtu_resp(pdu, plen, &mtu)) {
    cb_ret_val = BL_PROTOCOL_ERROR;
    strcpy(cb_ret_msg, "MTU exchange callback: PROTOCOL ERROR\n");
    goto error;
  }

  mtu = MIN(mtu, opt_mtu);
  /* Set new value for MTU in client */
  if (!g_attrib_set_mtu(attrib, mtu)) {
    cb_ret_val = BL_REQUEST_FAIL_ERROR;
    strcpy(cb_ret_msg, "MTU exchange callback: Unable to set new MTU value "
           "in client\n");
  } else {
    sprintf(cb_ret_msg, "MTU exchange callback: Success: %d\n", mtu);
    cb_ret_val = BL_NO_ERROR;
  }
 error:
  g_mutex_unlock(pending_callback);
  printf_dbg("[CB] OUT exchange_mtu_cb\n");
}
Пример #3
0
static void exchange_mtu_cb(guint8 status, const guint8 *pdu, guint16 plen,
                            gpointer user_data)
{
    uint16_t mtu;

    if (status != 0) {
        printf("Exchange MTU Request failed: %s\n",
               att_ecode2str(status));
        goto done;
    }

    if (!dec_mtu_resp(pdu, plen, &mtu)) {
        printf("Protocol error\n");
        goto done;
    }

    mtu = MIN(mtu, opt_mtu);
    /* Set new value for MTU in client */
    if (g_attrib_set_mtu(attrib, mtu))
        printf("MTU was exchanged successfully: %d\n", mtu);
    else
        printf("Error exchanging MTU\n");

done:
    printf("\r%s", get_prompt());
    fflush(stdout);
}
static void exchange_mtu_cb(
	guint8 status,
	guint8 const* pdu,
	guint16 plen,
	gpointer user_data)
{
	uint16_t mtu;
	user_data_t* ud = static_cast<user_data_t*>(user_data);

	if (status != 0) {
		std::cout << "Exchange MTU Request failed: " << att_ecode2str(status) << std::endl;
		disconnect(ud->attrib, ud->chan);
		g_main_loop_quit(event_loop);
		return;
	}

	if (!dec_mtu_resp(pdu, plen, &mtu)) {
		std::cout << "Protocol error" << std::endl;
		disconnect(ud->attrib, ud->chan);
		g_main_loop_quit(event_loop);
		return;
	}

	mtu = std::min(mtu, ud->mtu);
	/* Set new value for MTU in client */
	if (g_attrib_set_mtu(ud->attrib, mtu)) {
		std::cout << "MTU was exchanged successfully:" << mtu << std::endl;
		gatt_write_char(
			ud->attrib,
			ud->handle,
			reinterpret_cast<uint8_t const*>(&ud->value),
			sizeof(ud->value),
			gatt_write_char_cb,
			nullptr);
	}
	else {
		std::cout << "Error exchanging MTU" << std::endl;
		disconnect(ud->attrib, ud->chan);
		g_main_loop_quit(event_loop);
	}
}