Exemplo n.º 1
0
static uint8_t gb_svc_dme_peer_set(struct gb_operation *op) {
    struct gb_svc_dme_peer_set_request *req;
    struct gb_svc_dme_peer_set_response *resp;
    int rc;
    uint16_t attr, selector;
    uint32_t value;

    if (gb_operation_get_request_payload_size(op) < sizeof(*req)) {
        gb_error("dropping short message\n");
        return GB_OP_INVALID;
    }

    req = gb_operation_get_request_payload(op);
    resp = gb_operation_alloc_response(op, sizeof(*resp));
    if (!resp) {
        return GB_OP_NO_MEMORY;
    }

    attr = le16_to_cpu(req->attr);
    selector = le16_to_cpu(req->selector);
    value = le32_to_cpu(req->value);

    rc = svc_dme_peer_set(req->intf_id, attr, selector, value,
                          &resp->result_code);
    resp->result_code = cpu_to_le16(resp->result_code);

    return gb_errno_to_op_result(rc);
}
Exemplo n.º 2
0
/**
 * @brief Flush the camera capture
 *
 * The Flush operation calls camera driver to flush capture.
 *
 * @param operation pointer to structure of Greybus operation message
 * @return GB_OP_SUCCESS on success, error code on failure
 */
static uint8_t gb_camera_flush(struct gb_operation *operation)
{
    struct gb_camera_flush_response *response;
    uint32_t request_id = 0;
    int ret;

    lldbg("gb_camera_flush() + \n");

    if (info->state != STATE_STREAMING && info->state != STATE_CONFIGURED) {
        return GB_OP_INVALID;
    }

    ret = device_camera_flush(info->dev, &request_id);
    if (ret) {
        return gb_errno_to_op_result(ret);
    }

    info->state = STATE_CONFIGURED;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response) {
        return GB_OP_NO_MEMORY;
    }

    response->request_id = cpu_to_le32(request_id);
    lldbg("    request_id = %d + \n", request_id);

    lldbg("gb_camera_flush() + \n");

    return GB_OP_SUCCESS;
}
Exemplo n.º 3
0
static uint8_t gb_control_get_ids(struct gb_operation *operation)
{
    struct gb_control_get_ids_response *response;
    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->fw_version =
            cpu_to_le32(CONFIG_VERSION_MAJOR << 16 | CONFIG_VERSION_MINOR);

#ifdef CONFIG_ARCH_UID
    /* Populate the UID from the microprocessor */
    up_getuid(&response->uid_high, &response->uid_low);
#endif

#ifdef CONFIG_ARCH_CHIPID
    up_getchipid(&response->unipro_mfg_id, &response->unipro_prod_id);
#endif

#ifdef CONFIG_ARCH_BOARDID
    up_getboardid(&response->ara_vend_id, &response->ara_prod_id);
#endif

    return GB_OP_SUCCESS;
}
Exemplo n.º 4
0
/**
 * @brief Get Camera capabilities
 *
 * This operation retrieves the list of capabilities of the Camera Module and
 * then returns to host.
 *
 * @param operation Pointer to structure of Greybus operation.
 * @return GB_OP_SUCCESS on success, error code on failure.
 */
static uint8_t gb_camera_capabilities(struct gb_operation *operation)
{
    struct gb_camera_capabilities_response *response;
    const uint8_t *caps;
    size_t size;
    int ret;

    lldbg("gb_camera_capabilities() + \n");

    if (info->state < STATE_UNCONFIGURED) {
        lldbg("state error %d \n", info->state);
        return GB_OP_INVALID;
    }

    /* Retrieve the capabilities and their size. */
    ret = device_camera_capabilities(info->dev, &size, &caps);
    if (ret) {
        return gb_errno_to_op_result(ret);
    }

    if (size > GB_MAX_PAYLOAD_SIZE) {
        return GB_OP_NO_MEMORY;
    }

    response = gb_operation_alloc_response(operation, sizeof(*response) + size);
    if (!response) {
        return GB_OP_NO_MEMORY;
    }

    memcpy(response->capabilities, caps, size);

    lldbg("gb_camera_capabilities() - \n");

    return GB_OP_SUCCESS;
}
Exemplo n.º 5
0
static uint8_t gb_control_get_manifest_size(struct gb_operation *operation)
{
    struct gb_control_get_manifest_size_response *response;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->size = cpu_to_le16(get_manifest_size());

    return GB_OP_SUCCESS;
}
Exemplo n.º 6
0
/**
 * @brief Protocol get version function.
 *
 * Returns the major and minor Greybus UART protocol version number supported
 * by the UART device.
 *
 * @param operation The pointer to structure of gb_operation.
 * @return GB_OP_SUCCESS on success, error code on failure.
 */
static uint8_t gb_uart_protocol_version(struct gb_operation *operation)
{
    struct gb_uart_proto_version_response *response = NULL;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->major = GB_UART_VERSION_MAJOR;
    response->minor = GB_UART_VERSION_MINOR;
    return GB_OP_SUCCESS;
}
Exemplo n.º 7
0
static uint8_t gb_control_interface_version(struct gb_operation *operation)
{
    struct gb_control_interface_version_response *response;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->major = le16_to_cpu(GB_INTERFACE_VERSION_MAJOR);
    response->minor = le16_to_cpu(GB_INTERFACE_VERSION_MINOR);

    return GB_OP_SUCCESS;
}
Exemplo n.º 8
0
static uint8_t gb_battery_max_voltage(struct gb_operation *operation)
{
    struct gb_battery_max_voltage_response *response;

    gb_info("%s()\n", __func__);

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->voltage = 3800;

    return GB_OP_SUCCESS;
}
Exemplo n.º 9
0
static uint8_t gb_battery_status(struct gb_operation *operation)
{
    struct gb_battery_status_response *response;

    gb_info("%s()\n", __func__);

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->status = GB_BATTERY_STATUS_FULL;

    return GB_OP_SUCCESS;
}
Exemplo n.º 10
0
static uint8_t gb_battery_technology(struct gb_operation *operation)
{
    struct gb_battery_technology_response *response;

    gb_info("%s()\n", __func__);

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->technology = GB_BATTERY_TECH_LIPO;

    return GB_OP_SUCCESS;
}
Exemplo n.º 11
0
static uint8_t gb_battery_capacity(struct gb_operation *operation)
{
    struct gb_battery_capacity_response *response;

    gb_info("%s()\n", __func__);

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->capacity = 150;

    return GB_OP_SUCCESS;
}
Exemplo n.º 12
0
static uint8_t gb_battery_shutdowntemp(struct gb_operation *operation)
{
    struct gb_battery_temperature_response *response;

    gb_info("%s()\n", __func__);

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->temperature = 50;

    return GB_OP_SUCCESS;
}
Exemplo n.º 13
0
static uint8_t gb_battery_protocol_version(struct gb_operation *operation)
{
    struct gb_battery_proto_version_response *response;

    gb_info("%s()\n", __func__);

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    response->major = GB_BATTERY_VERSION_MAJOR;
    response->minor = GB_BATTERY_VERSION_MINOR;

    return GB_OP_SUCCESS;
}
Exemplo n.º 14
0
/**
* @brief Get battery current voltage in microvolt .
*
* @param operation The pointer to structure of gb_operation.
*
* @return GB_OP_SUCCESS on success, error code on failure.
*/
static uint8_t gb_battery_voltage(struct gb_operation *operation)
{
    struct gb_battery_voltage_response *response;
    uint32_t voltage = 0;
    int ret = 0;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    ret = device_battery_voltage(batt_dev, &voltage);

    response->voltage = cpu_to_le32(voltage);

    return gb_errno_to_op_result(ret);
}
Exemplo n.º 15
0
/**
* @brief Get battery status.
*
* @param operation The pointer to structure of gb_operation.
*
* @return GB_OP_SUCCESS on success, error code on failure.
*/
static uint8_t gb_battery_status(struct gb_operation *operation)
{
    struct gb_battery_status_response *response;
    uint16_t status = 0;
    int ret = 0;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    ret = device_battery_status(batt_dev, &status);

    response->status = cpu_to_le16(status);

    return gb_errno_to_op_result(ret);
}
Exemplo n.º 16
0
/**
* @brief Get battery total capacity in mAh.
*
* @param operation The pointer to structure of gb_operation.
*
* @return GB_OP_SUCCESS on success, error code on failure.
*/
static uint8_t gb_battery_capacity(struct gb_operation *operation)
{
    struct gb_battery_capacity_response *response;
    uint32_t capacity = 0;
    int ret = 0;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    ret = device_battery_total_capacity(batt_dev, &capacity);

    response->capacity = cpu_to_le32(capacity);

    return gb_errno_to_op_result(ret);
}
Exemplo n.º 17
0
/**
* @brief Get battery shutdown temperature in 0.1 Celsius.
*
* @param operation The pointer to structure of gb_operation.
*
* @return GB_OP_SUCCESS on success, error code on failure.
*/
static uint8_t gb_battery_shutdown_temp(struct gb_operation *operation)
{
    struct gb_battery_shutdown_temperature_response *response;
    int temp = 0;
    int ret = 0;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    ret = device_battery_shutdown_temp(batt_dev, &temp);

    response->temperature = cpu_to_le32(temp);

    return gb_errno_to_op_result(ret);
}
Exemplo n.º 18
0
static uint8_t gb_control_timesync_get_last_event(
                                                struct gb_operation *operation)
{
    uint64_t frame_time;
    struct gb_control_timesync_get_last_event_response *response;
    int retval;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    retval = timesync_get_last_event(&frame_time);
    if (!retval)
        response->frame_time = cpu_to_le64(frame_time);
    return gb_errno_to_op_result(retval);
}
Exemplo n.º 19
0
/**
* @brief Get battery current in microampere.
*
* @param operation The pointer to structure of gb_operation.
*
* @return GB_OP_SUCCESS on success, error code on failure.
*/
static uint8_t gb_battery_current(struct gb_operation *operation)
{
    struct gb_battery_current_response *response;
    int current = 0;
    int ret = 0;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    ret = device_battery_current(batt_dev, &current);

    response->current = cpu_to_le32(current);

    return gb_errno_to_op_result(ret);
}
Exemplo n.º 20
0
/**
 * @brief Get the battery adapter control technology type.
 *
 * @param operation The pointer to structure of gb_operation.
 *
 * @return GB_OP_SUCCESS on success, error code on failure.
 */
static uint8_t gb_battery_technology(struct gb_operation *operation)
{
    struct gb_battery_technology_response *response;
    uint32_t tech = 0;
    int ret = 0;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    ret = device_battery_technology(batt_dev, &tech);

    response->technology = cpu_to_le32(tech);

    return gb_errno_to_op_result(ret);
}
Exemplo n.º 21
0
Arquivo: ptp.c Projeto: jksim/nuttx
static uint8_t gb_ptp_power_source(struct gb_operation *operation)
{
    struct gb_ptp_power_source_response *response;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

#if !defined (CONFIG_GREYBUS_PTP_INT_SND_NEVER) || defined (CONFIG_GREYBUS_PTP_EXT_SUPPORTED)
    if (device_ptp_power_source(ptp_info->dev, &response->source))
        return GB_OP_UNKNOWN_ERROR;
#else
    response->source = PTP_POWER_AVAILABLE_NONE;
#endif

    return GB_OP_SUCCESS;
}
Exemplo n.º 22
0
Arquivo: ptp.c Projeto: jksim/nuttx
static uint8_t gb_ptp_power_required(struct gb_operation *operation)
{
    struct gb_ptp_power_required_response *response;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

#ifndef CONFIG_GREYBUS_PTP_INT_RCV_NEVER
    if (device_ptp_power_required(ptp_info->dev, &response->required))
        return GB_OP_UNKNOWN_ERROR;
#else
    response->required = PTP_POWER_NOT_REQUIRED;
#endif

    return GB_OP_SUCCESS;
}
Exemplo n.º 23
0
/**
 * @brief Returns the major and minor Greybus Camera Protocol version number
 *
 * This operation returns the major and minor version number supported by
 * Greybus Camera Protocol
 *
 * @param operation Pointer to structure of Greybus operation.
 * @return GB_OP_SUCCESS on success, error code on failure.
 */
static uint8_t gb_camera_protocol_version(struct gb_operation *operation)
{
    struct gb_camera_version_response *response;

    lldbg("gb_camera_protocol_version() + \n");

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response) {
        return GB_OP_NO_MEMORY;
    }

    response->major = GB_CAMERA_VERSION_MAJOR;
    response->minor = GB_CAMERA_VERSION_MINOR;

    lldbg("gb_camera_protocol_version() - \n");

    return GB_OP_SUCCESS;
}
Exemplo n.º 24
0
static uint8_t __attribute__((unused)) gb_control_intf_pwr_set(struct gb_operation *operation)
{
    struct gb_control_intf_pwr_set_request *request;
    struct gb_control_intf_pwr_set_response *response;

    if (gb_operation_get_request_payload_size(operation) < sizeof(*request)) {
        gb_error("dropping short message\n");
        return GB_OP_INVALID;
    }

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

    request = gb_operation_get_request_payload(operation);
    (void)request;

    return GB_OP_PROTOCOL_BAD;
}
Exemplo n.º 25
0
Arquivo: ptp.c Projeto: jksim/nuttx
static uint8_t gp_ptp_get_functionality(struct gb_operation *operation)
{
    struct gb_ptp_get_functionality_response *response;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

#if defined (CONFIG_GREYBUS_PTP_INT_SND_NEVER)
    response->int_snd = PTP_INT_SND_NEVER;
#elif defined (CONFIG_GREYBUS_PTP_INT_SND_SUPPLEMENTAL)
    response->int_snd = PTP_INT_SND_SUPPLEMENTAL;
#elif defined (CONFIG_GREYBUS_PTP_INT_SND_LOW_BATT_SAVER)
    response->int_snd = PTP_INT_SND_LOW_BATT_SAVER;
#else
    #error "define send power capabilities"
#endif

#if defined (CONFIG_GREYBUS_PTP_INT_RCV_NEVER)
    response->int_rcv = PTP_INT_RCV_NEVER;
#elif defined (CONFIG_GREYBUS_PTP_INT_RCV_FIRST)
    response->int_rcv = PTP_INT_RCV_FIRST;
#elif defined (CONFIG_GREYBUS_PTP_INT_RCV_SECOND)
    response->int_rcv = PTP_INT_RCV_SECOND;
#elif defined (CONFIG_GREYBUS_PTP_INT_RCV_PARALLEL)
    response->int_rcv = PTP_INT_RCV_PARALLEL;
#else
    #error "define receive power capabilities"
#endif

#if defined (CONFIG_GREYBUS_PTP_EXT_NONE)
    response->ext = PTP_EXT_NONE;
#elif defined (CONFIG_GREYBUS_PTP_EXT_SUPPORTED)
    response->ext = PTP_EXT_SUPPORTED;
#else
    #error "define external power sources capabilities"
#endif

    response->unused = 0;

    return GB_OP_SUCCESS;
}
Exemplo n.º 26
0
static uint8_t gb_control_get_manifest(struct gb_operation *operation)
{
    struct gb_control_get_manifest_response *response;
    struct greybus_manifest_header *mh;
    int size = get_manifest_size();

    response = gb_operation_alloc_response(operation, size);
    if (!response)
        return GB_OP_NO_MEMORY;

    mh = get_manifest_blob();
    if (!mh) {
        gb_error("Failed to get a valid manifest\n");
        return GB_OP_INVALID;
    }

    memcpy(response->data, mh, size);

    return GB_OP_SUCCESS;
}
Exemplo n.º 27
0
Arquivo: ptp.c Projeto: jksim/nuttx
static uint8_t gb_ptp_get_max_output_current(struct gb_operation *operation)
{
    struct gb_ptp_get_max_output_current_response *response;
    uint32_t current;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

#if !defined (CONFIG_GREYBUS_PTP_INT_SND_NEVER) || defined (CONFIG_GREYBUS_PTP_EXT_SUPPORTED)
    if (device_ptp_get_max_output_current(ptp_info->dev, &current))
        return GB_OP_UNKNOWN_ERROR;
#else
    current = 0;
#endif

    response->current = cpu_to_le32(current);

    return GB_OP_SUCCESS;
}
Exemplo n.º 28
0
Arquivo: ptp.c Projeto: jksim/nuttx
static uint8_t gb_ptp_ext_power_present(struct gb_operation *operation)
{
    struct gb_ptp_ext_power_present_response *response;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response)
        return GB_OP_NO_MEMORY;

#if defined (CONFIG_GREYBUS_PTP_EXT_SUPPORTED)
    if (device_ptp_ext_power_present(ptp_info->dev, &response->present))
        return GB_OP_UNKNOWN_ERROR;

    if (ptp_info->host_major == PTP_EXT_POWER_PRESENT_LAST_SUPPORTED_MAJOR &&
        ptp_info->host_minor <=  PTP_EXT_POWER_PRESENT_LAST_SUPPORTED_MINOR &&
        response->present != PTP_EXT_POWER_NOT_PRESENT)
        response->present = PTP_EXT_POWER_PRESENT;
#else
    response->present = PTP_EXT_POWER_NOT_PRESENT;
#endif

    return GB_OP_SUCCESS;
}
Exemplo n.º 29
0
/**
 * @brief Get Camera capabilities
 *
 * This operation retrieves the list of capabilities of the Camera Module and
 * then returns to host.
 *
 * @param operation Pointer to structure of Greybus operation.
 * @return GB_OP_SUCCESS on success, error code on failure.
 */
static uint8_t gb_camera_capabilities(struct gb_operation *operation)
{
    struct gb_camera_capabilities_response *response;
    uint8_t *capabilities;
    uint16_t size;
    int ret;

    lldbg("gb_camera_capabilities() + \n");

    if (info->state < STATE_UNCONFIGURED) {
        lldbg("state error %d \n", info->state);
        return GB_OP_INVALID;
    }

    ret = device_camera_get_required_size(info->dev, SIZE_CAPABILITIES, &size);
    if (ret) {
        return gb_errno_to_op_result(ret);
    }

    response = gb_operation_alloc_response(operation, sizeof(*response) + size);
    if (!response) {
        return GB_OP_NO_MEMORY;
    }

    /* camera module capabilities */
    ret = device_camera_capabilities(info->dev, &size, capabilities);
    if (ret) {
        return gb_errno_to_op_result(ret);
    }

    response->size = cpu_to_le16(size);
    memcpy(response->capabilities, &capabilities, size);

    lldbg("gb_camera_capabilities() - \n");

    return GB_OP_SUCCESS;
}
Exemplo n.º 30
0
Arquivo: ptp.c Projeto: jksim/nuttx
static uint8_t gb_ptp_protocol_version(struct gb_operation *operation)
{
    struct gb_ptp_proto_version_request *request;
    struct gb_ptp_proto_version_response *response;

    if (gb_operation_get_request_payload_size(operation) < sizeof(*request)) {
        gb_error("dropping short message\n");
        return GB_OP_INVALID;
    }

    request = gb_operation_get_request_payload(operation);
    ptp_info->host_major = request->major;
    ptp_info->host_minor = request->minor;

    response = gb_operation_alloc_response(operation, sizeof(*response));
    if (!response) {
        return GB_OP_NO_MEMORY;
    }

    response->major = GB_PTP_VERSION_MAJOR;
    response->minor = GB_PTP_VERSION_MINOR;

    return GB_OP_SUCCESS;
}