Commit 80ccb51a authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] siano: simplify message endianness logic

Currently, every time a message is sent or received, the endiannes
need to be fixed on big endian machines. This is currently done
on every call to the send API, and on every msg reception logic.
Instead of doing that, move it to the send/receive functions.
That simplifies the logic and avoids the risk of forgetting to
fix it somewhere.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent fe802fd9
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "smscoreapi.h" #include "smscoreapi.h"
#include "sms-cards.h" #include "sms-cards.h"
#include "smsir.h" #include "smsir.h"
#include "smsendian.h"
static int sms_dbg; static int sms_dbg;
module_param_named(debug, sms_dbg, int, 0644); module_param_named(debug, sms_dbg, int, 0644);
...@@ -807,8 +806,6 @@ static int smscore_init_ir(struct smscore_device_t *coredev) ...@@ -807,8 +806,6 @@ static int smscore_init_ir(struct smscore_device_t *coredev)
msg->msgData[0] = coredev->ir.controller; msg->msgData[0] = coredev->ir.controller;
msg->msgData[1] = coredev->ir.timeout; msg->msgData[1] = coredev->ir.timeout;
smsendian_handle_tx_message(
(struct SmsMsgHdr_ST2 *)msg);
rc = smscore_sendrequest_and_wait(coredev, msg, rc = smscore_sendrequest_and_wait(coredev, msg,
msg->xMsgHeader. msgLength, msg->xMsgHeader. msgLength,
&coredev->ir_init_done); &coredev->ir_init_done);
...@@ -853,7 +850,6 @@ int smscore_configure_board(struct smscore_device_t *coredev) ...@@ -853,7 +850,6 @@ int smscore_configure_board(struct smscore_device_t *coredev)
MtuMsg.xMsgHeader.msgLength = sizeof(MtuMsg); MtuMsg.xMsgHeader.msgLength = sizeof(MtuMsg);
MtuMsg.msgData[0] = board->mtu; MtuMsg.msgData[0] = board->mtu;
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&MtuMsg);
coredev->sendrequest_handler(coredev->context, &MtuMsg, coredev->sendrequest_handler(coredev->context, &MtuMsg,
sizeof(MtuMsg)); sizeof(MtuMsg));
} }
...@@ -867,7 +863,6 @@ int smscore_configure_board(struct smscore_device_t *coredev) ...@@ -867,7 +863,6 @@ int smscore_configure_board(struct smscore_device_t *coredev)
sizeof(CrysMsg)); sizeof(CrysMsg));
CrysMsg.msgData[0] = board->crystal; CrysMsg.msgData[0] = board->crystal;
smsendian_handle_tx_message((struct SmsMsgHdr_S *)&CrysMsg);
coredev->sendrequest_handler(coredev->context, &CrysMsg, coredev->sendrequest_handler(coredev->context, &CrysMsg,
sizeof(CrysMsg)); sizeof(CrysMsg));
} }
...@@ -989,7 +984,6 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev, ...@@ -989,7 +984,6 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
/* Entry point */ /* Entry point */
msg->msgData[1] = firmware->Length; msg->msgData[1] = firmware->Length;
msg->msgData[2] = 0; /* Regular checksum*/ msg->msgData[2] = 0; /* Regular checksum*/
smsendian_handle_tx_message(msg);
rc = smscore_sendrequest_and_wait(coredev, msg, rc = smscore_sendrequest_and_wait(coredev, msg,
msg->xMsgHeader.msgLength, msg->xMsgHeader.msgLength,
&coredev->data_validity_done); &coredev->data_validity_done);
...@@ -1013,14 +1007,12 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev, ...@@ -1013,14 +1007,12 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
TriggerMsg->msgData[3] = 0; /* Parameter */ TriggerMsg->msgData[3] = 0; /* Parameter */
TriggerMsg->msgData[4] = 4; /* Task ID */ TriggerMsg->msgData[4] = 4; /* Task ID */
smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
rc = smscore_sendrequest_and_wait(coredev, TriggerMsg, rc = smscore_sendrequest_and_wait(coredev, TriggerMsg,
TriggerMsg->xMsgHeader.msgLength, TriggerMsg->xMsgHeader.msgLength,
&coredev->trigger_done); &coredev->trigger_done);
} else { } else {
SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_EXEC_REQ, SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_EXEC_REQ,
sizeof(struct SmsMsgHdr_ST)); sizeof(struct SmsMsgHdr_ST));
smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
rc = coredev->sendrequest_handler(coredev->context, msg, rc = coredev->sendrequest_handler(coredev->context, msg,
msg->xMsgHeader.msgLength); msg->xMsgHeader.msgLength);
} }
...@@ -1305,7 +1297,6 @@ int smscore_init_device(struct smscore_device_t *coredev, int mode) ...@@ -1305,7 +1297,6 @@ int smscore_init_device(struct smscore_device_t *coredev, int mode)
sizeof(struct SmsMsgData_ST)); sizeof(struct SmsMsgData_ST));
msg->msgData[0] = mode; msg->msgData[0] = mode;
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
rc = smscore_sendrequest_and_wait(coredev, msg, rc = smscore_sendrequest_and_wait(coredev, msg,
msg->xMsgHeader. msgLength, msg->xMsgHeader. msgLength,
&coredev->init_device_done); &coredev->init_device_done);
...@@ -1526,8 +1517,6 @@ void smscore_onresponse(struct smscore_device_t *coredev, ...@@ -1526,8 +1517,6 @@ void smscore_onresponse(struct smscore_device_t *coredev,
rc = client->onresponse_handler(client->context, cb); rc = client->onresponse_handler(client->context, cb);
if (rc < 0) { if (rc < 0) {
smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);
switch (phdr->msgType) { switch (phdr->msgType) {
case MSG_SMS_ISDBT_TUNE_RES: case MSG_SMS_ISDBT_TUNE_RES:
break; break;
...@@ -2008,7 +1997,6 @@ int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum, ...@@ -2008,7 +1997,6 @@ int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
pMsg->msgData[5] = 0; pMsg->msgData[5] = 0;
} }
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen, rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
&coredev->gpio_configuration_done); &coredev->gpio_configuration_done);
...@@ -2058,7 +2046,6 @@ int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum, ...@@ -2058,7 +2046,6 @@ int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
pMsg->msgData[1] = NewLevel; pMsg->msgData[1] = NewLevel;
/* Send message to SMS */ /* Send message to SMS */
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen, rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
&coredev->gpio_set_level_done); &coredev->gpio_set_level_done);
...@@ -2107,7 +2094,6 @@ int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum, ...@@ -2107,7 +2094,6 @@ int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum,
pMsg->msgData[1] = 0; pMsg->msgData[1] = 0;
/* Send message to SMS */ /* Send message to SMS */
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen, rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
&coredev->gpio_get_level_done); &coredev->gpio_get_level_done);
......
...@@ -29,7 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -29,7 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dvb_frontend.h" #include "dvb_frontend.h"
#include "smscoreapi.h" #include "smscoreapi.h"
#include "smsendian.h"
#include "sms-cards.h" #include "sms-cards.h"
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
...@@ -324,8 +323,6 @@ static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb) ...@@ -324,8 +323,6 @@ static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
/*u32 MsgDataLen = phdr->msgLength - sizeof(struct SmsMsgHdr_ST);*/ /*u32 MsgDataLen = phdr->msgLength - sizeof(struct SmsMsgHdr_ST);*/
bool is_status_update = false; bool is_status_update = false;
smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);
switch (phdr->msgType) { switch (phdr->msgType) {
case MSG_SMS_DVBT_BDA_DATA: case MSG_SMS_DVBT_BDA_DATA:
dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1), dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1),
...@@ -545,7 +542,6 @@ static int smsdvb_start_feed(struct dvb_demux_feed *feed) ...@@ -545,7 +542,6 @@ static int smsdvb_start_feed(struct dvb_demux_feed *feed)
PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
PidMsg.msgData[0] = feed->pid; PidMsg.msgData[0] = feed->pid;
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
return smsclient_sendrequest(client->smsclient, return smsclient_sendrequest(client->smsclient,
&PidMsg, sizeof(PidMsg)); &PidMsg, sizeof(PidMsg));
} }
...@@ -566,7 +562,6 @@ static int smsdvb_stop_feed(struct dvb_demux_feed *feed) ...@@ -566,7 +562,6 @@ static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
PidMsg.msgData[0] = feed->pid; PidMsg.msgData[0] = feed->pid;
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
return smsclient_sendrequest(client->smsclient, return smsclient_sendrequest(client->smsclient,
&PidMsg, sizeof(PidMsg)); &PidMsg, sizeof(PidMsg));
} }
...@@ -577,7 +572,6 @@ static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client, ...@@ -577,7 +572,6 @@ static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
{ {
int rc; int rc;
smsendian_handle_tx_message((struct SmsMsgHdr_ST *)buffer);
rc = smsclient_sendrequest(client->smsclient, buffer, size); rc = smsclient_sendrequest(client->smsclient, buffer, size);
if (rc < 0) if (rc < 0)
return rc; return rc;
...@@ -606,8 +600,6 @@ static int smsdvb_send_statistics_request(struct smsdvb_client_t *client) ...@@ -606,8 +600,6 @@ static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
else else
Msg.msgType = MSG_SMS_GET_STATISTICS_REQ; Msg.msgType = MSG_SMS_GET_STATISTICS_REQ;
smsendian_handle_tx_message((struct SmsMsgHdr_S *)&Msg);
rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
&client->stats_done); &client->stats_done);
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "smscoreapi.h" #include "smscoreapi.h"
#include "sms-cards.h" #include "sms-cards.h"
#include "smsendian.h"
/* Registers */ /* Registers */
...@@ -97,6 +98,7 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size) ...@@ -97,6 +98,7 @@ static int smssdio_sendrequest(void *context, void *buffer, size_t size)
sdio_claim_host(smsdev->func); sdio_claim_host(smsdev->func);
smsendian_handle_tx_message((struct SmsMsgData_ST *) buffer);
while (size >= smsdev->func->cur_blksize) { while (size >= smsdev->func->cur_blksize) {
ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA, ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
buffer, smsdev->func->cur_blksize); buffer, smsdev->func->cur_blksize);
...@@ -231,6 +233,7 @@ static void smssdio_interrupt(struct sdio_func *func) ...@@ -231,6 +233,7 @@ static void smssdio_interrupt(struct sdio_func *func)
cb->size = hdr->msgLength; cb->size = hdr->msgLength;
cb->offset = 0; cb->offset = 0;
smsendian_handle_rx_message((struct SmsMsgData_ST *) cb->p);
smscore_onresponse(smsdev->coredev, cb); smscore_onresponse(smsdev->coredev, cb);
} }
......
...@@ -129,6 +129,8 @@ static void smsusb_onresponse(struct urb *urb) ...@@ -129,6 +129,8 @@ static void smsusb_onresponse(struct urb *urb)
smscore_translate_msg(phdr->msgType), smscore_translate_msg(phdr->msgType),
phdr->msgType, phdr->msgLength); phdr->msgType, phdr->msgLength);
smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr);
smscore_onresponse(dev->coredev, surb->cb); smscore_onresponse(dev->coredev, surb->cb);
surb->cb = NULL; surb->cb = NULL;
} else { } else {
...@@ -207,13 +209,14 @@ static int smsusb_sendrequest(void *context, void *buffer, size_t size) ...@@ -207,13 +209,14 @@ static int smsusb_sendrequest(void *context, void *buffer, size_t size)
struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer; struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
int dummy; int dummy;
if (dev->state != SMSUSB_ACTIVE)
return -ENOENT;
sms_debug("sending %s(%d) size: %d", sms_debug("sending %s(%d) size: %d",
smscore_translate_msg(phdr->msgType), phdr->msgType, smscore_translate_msg(phdr->msgType), phdr->msgType,
phdr->msgLength); phdr->msgLength);
if (dev->state != SMSUSB_ACTIVE) smsendian_handle_tx_message((struct SmsMsgData_ST *) phdr);
return -ENOENT;
smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer); smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer);
return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2), return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
buffer, size, &dummy, 1000); buffer, size, &dummy, 1000);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment