int sap_status_ind(void *sap_device, uint8_t status_change) { 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 sc 0x%02x", conn->state, conn->processing_req, status_change); /* Might be need to change state to connected after ongoing call.*/ if (conn->state == SAP_STATE_CONNECT_MODEM_BUSY && status_change == SAP_STATUS_CHANGE_CARD_RESET) sap_set_connected(conn); if (conn->state != SAP_STATE_CONNECTED && conn->state != SAP_STATE_GRACEFUL_DISCONNECT) return 0; memset(buf, 0, sizeof(buf)); msg->id = SAP_STATUS_IND; msg->nparam = 0x01; /* Add status change. */ param->id = SAP_PARAM_ID_STATUS_CHANGE; param->len = htons(SAP_PARAM_ID_STATUS_CHANGE_LEN); *param->val = status_change; size += PARAMETER_SIZE(SAP_PARAM_ID_STATUS_CHANGE_LEN); return send_message(sap_device, buf, size); }
int sap_connect_rsp(void *sap_device, 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 status 0x%02x", conn->state, conn->processing_req, status); if (conn->state != SAP_STATE_CONNECT_IN_PROGRESS) return -EPERM; memset(buf, 0, sizeof(buf)); msg->id = SAP_CONNECT_RESP; msg->nparam = 0x01; /* Add connection status */ param->id = SAP_PARAM_ID_CONN_STATUS; param->len = htons(SAP_PARAM_ID_CONN_STATUS_LEN); *param->val = status; size += PARAMETER_SIZE(SAP_PARAM_ID_CONN_STATUS_LEN); switch (status) { case SAP_STATUS_OK: sap_set_connected(server); break; case SAP_STATUS_OK_ONGOING_CALL: DBG("ongoing call. Wait for reset indication!"); conn->state = SAP_STATE_CONNECT_MODEM_BUSY; break; case SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED: /* Add MaxMsgSize */ msg->nparam++; param = (struct sap_parameter *) &buf[size]; param->id = SAP_PARAM_ID_MAX_MSG_SIZE; param->len = htons(SAP_PARAM_ID_MAX_MSG_SIZE_LEN); put_be16(SAP_BUF_SIZE, ¶m->val); size += PARAMETER_SIZE(SAP_PARAM_ID_MAX_MSG_SIZE_LEN); /* fall */ default: conn->state = SAP_STATE_DISCONNECTED; /* Timer will shutdown channel if client doesn't send * CONNECT_REQ or doesn't shutdown channel itself.*/ start_guard_timer(server, SAP_TIMER_NO_ACTIVITY); break; } conn->processing_req = SAP_NO_REQ; return send_message(conn, buf, size); }
int sap_connect_rsp(void *sap_device, uint8_t status, uint16_t maxmsgsize) { 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 status 0x%02x", conn->state, conn->processing_req, status); if (conn->state != SAP_STATE_CONNECT_IN_PROGRESS) return -EPERM; memset(buf, 0, sizeof(buf)); msg->id = SAP_CONNECT_RESP; msg->nparam = 0x01; /* Add connection status */ param->id = SAP_PARAM_ID_CONN_STATUS; param->len = htons(SAP_PARAM_ID_CONN_STATUS_LEN); *param->val = status; size += PARAMETER_SIZE(SAP_PARAM_ID_CONN_STATUS_LEN); /* Add MaxMsgSize */ if (maxmsgsize) { uint16_t *len; msg->nparam++; param = (struct sap_parameter *) &buf[size]; param->id = SAP_PARAM_ID_MAX_MSG_SIZE; param->len = htons(SAP_PARAM_ID_MAX_MSG_SIZE_LEN); len = (uint16_t *) ¶m->val; *len = htons(maxmsgsize); size += PARAMETER_SIZE(SAP_PARAM_ID_MAX_MSG_SIZE_LEN); } if (status == SAP_STATUS_OK) { sap_set_connected(conn); } else if (status == SAP_STATUS_OK_ONGOING_CALL) { DBG("ongoing call. Wait for reset indication!"); conn->state = SAP_STATE_CONNECT_MODEM_BUSY; } else { conn->state = SAP_STATE_DISCONNECTED; /* Timer will shutdown channel if client doesn't send * CONNECT_REQ or doesn't shutdown channel itself.*/ start_guard_timer(conn, SAP_TIMER_NO_ACTIVITY); } conn->processing_req = SAP_NO_REQ; return send_message(sap_device, buf, size); }
int sap_status_ind(void *sap_device, uint8_t status_change) { 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 sc 0x%02x", conn->state, conn->processing_req, status_change); switch (conn->state) { case SAP_STATE_CONNECT_MODEM_BUSY: if (status_change != SAP_STATUS_CHANGE_CARD_RESET) break; /* Change state to connected after ongoing call ended */ sap_set_connected(server); /* fall */ case SAP_STATE_CONNECTED: case SAP_STATE_GRACEFUL_DISCONNECT: memset(buf, 0, sizeof(buf)); msg->id = SAP_STATUS_IND; msg->nparam = 0x01; /* Add status change. */ param->id = SAP_PARAM_ID_STATUS_CHANGE; param->len = htons(SAP_PARAM_ID_STATUS_CHANGE_LEN); *param->val = status_change; size += PARAMETER_SIZE(SAP_PARAM_ID_STATUS_CHANGE_LEN); return send_message(conn, buf, size); case SAP_STATE_DISCONNECTED: case SAP_STATE_CONNECT_IN_PROGRESS: case SAP_STATE_IMMEDIATE_DISCONNECT: case SAP_STATE_CLIENT_DISCONNECT: break; } return 0; }