int sap_transport_protocol_rsp(void *sap_device, uint8_t result) { struct sap_connection *conn = sap_device; char buf[SAP_BUF_SIZE]; struct sap_message *msg = (struct sap_message *) buf; size_t size = sizeof(struct sap_message); if (!conn) return -EINVAL; DBG("state %d pr 0x%02x result 0x%02x", conn->state, conn->processing_req, result); if (conn->processing_req != SAP_SET_TRANSPORT_PROTOCOL_REQ) return 0; memset(buf, 0, sizeof(buf)); msg->id = SAP_SET_TRANSPORT_PROTOCOL_RESP; msg->nparam = 0x01; size += add_result_parameter(result, msg->param); conn->processing_req = SAP_NO_REQ; return send_message(sap_device, buf, size); }
int sap_reset_sim_rsp(void *sap_device, uint8_t result) { struct sap_server *server = sap_device; struct sap_connection *conn = server->conn; char buf[SAP_BUF_SIZE]; struct sap_message *msg = (struct sap_message *) buf; size_t size = sizeof(struct sap_message); if (!conn) return -EINVAL; DBG("state %d pr 0x%02x result 0x%02x", conn->state, conn->processing_req, result); if (conn->processing_req != SAP_RESET_SIM_REQ) return 0; memset(buf, 0, sizeof(buf)); msg->id = SAP_RESET_SIM_RESP; msg->nparam = 0x01; size += add_result_parameter(result, msg->param); conn->processing_req = SAP_NO_REQ; return send_message(conn, buf, size); }
int sap_transfer_atr_rsp(void *sap_device, uint8_t result, uint8_t *atr, uint16_t length) { struct sap_server *server = sap_device; struct sap_connection *conn = server->conn; char buf[SAP_BUF_SIZE]; struct sap_message *msg = (struct sap_message *) buf; struct sap_parameter *param = (struct sap_parameter *) msg->param; size_t size = sizeof(struct sap_message); if (!conn) return -EINVAL; DBG("result 0x%02x state %d pr 0x%02x len %d", result, conn->state, conn->processing_req, length); if (conn->processing_req != SAP_TRANSFER_ATR_REQ) return 0; if (result == SAP_RESULT_OK && (!atr || (atr && length == 0x00))) return -EINVAL; memset(buf, 0, sizeof(buf)); msg->id = SAP_TRANSFER_ATR_RESP; msg->nparam = 0x01; size += add_result_parameter(result, param); /* Add ATR response */ if (result == SAP_RESULT_OK) { msg->nparam++; param = (struct sap_parameter *) &buf[size]; param->id = SAP_PARAM_ID_ATR; param->len = htons(length); size += PARAMETER_SIZE(length); if (size > SAP_BUF_SIZE) return -EOVERFLOW; memcpy(param->val, atr, length); } conn->processing_req = SAP_NO_REQ; return send_message(conn, buf, size); }
int sap_transfer_apdu_rsp(void *sap_device, uint8_t result, uint8_t *apdu, uint16_t length) { struct sap_connection *conn = sap_device; char buf[SAP_BUF_SIZE]; struct sap_message *msg = (struct sap_message *) buf; struct sap_parameter *param = (struct sap_parameter *) msg->param; size_t size = sizeof(struct sap_message); if (!conn) return -EINVAL; DBG("state %d pr 0x%02x", conn->state, conn->processing_req); if (conn->processing_req != SAP_TRANSFER_APDU_REQ) return 0; if (result == SAP_RESULT_OK && (!apdu || (apdu && length == 0x00))) return -EINVAL; memset(buf, 0, sizeof(buf)); msg->id = SAP_TRANSFER_APDU_RESP; msg->nparam = 0x01; size += add_result_parameter(result, param); /* Add APDU response. */ if (result == SAP_RESULT_OK) { msg->nparam++; param = (struct sap_parameter *) &buf[size]; param->id = SAP_PARAM_ID_RESPONSE_APDU; param->len = htons(length); size += PARAMETER_SIZE(length); if (size > SAP_BUF_SIZE) return -EOVERFLOW; memcpy(param->val, apdu, length); } conn->processing_req = SAP_NO_REQ; return send_message(sap_device, buf, size); }
int sap_transfer_card_reader_status_rsp(void *sap_device, uint8_t result, uint8_t status) { struct sap_server *server = sap_device; struct sap_connection *conn = server->conn; char buf[SAP_BUF_SIZE]; struct sap_message *msg = (struct sap_message *) buf; struct sap_parameter *param = (struct sap_parameter *) msg->param; size_t size = sizeof(struct sap_message); if (!conn) return -EINVAL; DBG("state %d pr 0x%02x result 0x%02x", conn->state, conn->processing_req, result); if (conn->processing_req != SAP_TRANSFER_CARD_READER_STATUS_REQ) return 0; memset(buf, 0, sizeof(buf)); msg->id = SAP_TRANSFER_CARD_READER_STATUS_RESP; msg->nparam = 0x01; size += add_result_parameter(result, param); /* Add card reader status. */ if (result == SAP_RESULT_OK) { msg->nparam++; param = (struct sap_parameter *) &buf[size]; param->id = SAP_PARAM_ID_CARD_READER_STATUS; param->len = htons(SAP_PARAM_ID_CARD_READER_STATUS_LEN); *param->val = status; size += PARAMETER_SIZE(SAP_PARAM_ID_CARD_READER_STATUS_LEN); } conn->processing_req = SAP_NO_REQ; return send_message(conn, buf, size); }