123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- #include "pocCmds.h"
- #include "protobuf-c.h"
- #include "ptt.pb-c.h"
- #include "poc_code.h"
- #include "poc_tcp.h"
- #include <string.h>
- #include <stdio.h>
- #include "mallocSw.h"//if no this file,just include stdlib.h if system supported
- #define PLATFORM "CAT 1"
- #define DEVICE "LS"
- //Login
- static T_UINT16 pa_login(T_UINT8 *buffer, T_UINT16 len, T_INT8 *account, T_INT8 *pass){
- Login _login;
- T_UINT8 *pb=NULL;
- T_UINT16 rlen;
-
- login__init(&_login);
- _login.account=account;
- _login.password=pass;
- _login.platform=PLATFORM;
- _login.device=DEVICE;
- _login.meid=pass;
- _login.has_expect_payload=1;
- _login.expect_payload=CODEC_EVRC_8K;
- rlen=login__get_packed_size(&_login);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb==NULL){
- wlog_error("login malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
- rlen=login__pack(&_login, pb);
- }else rlen=0;
- rlen=packet_encode(buffer, len, U_LOGIN, pb, rlen);
- if(NULL != pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryLogin(T_INT32 tcpSocket, T_UINT32 PSN, T_INT8 *pass){
- T_UINT8 buff[80];//实际只需要66个字节左右
- T_INT8 psn[20];
- T_UINT16 plen;
- memset(buff,0,sizeof(buff));
- snprintf(psn, sizeof(psn), "%d",PSN);
- plen=pa_login(buff,sizeof(buff),psn,pass);
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //Logout
- static T_UINT16 pa_logout(T_BYTE *buf, T_UINT16 len){
- Logout _logout;
- T_UINT8 *pb=NULL;
- T_UINT16 rlen;
- logout__init(&_logout);
- rlen=logout__get_packed_size(&_logout);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL){
- wlog_error("logout malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
- rlen=logout__pack(&_logout,pb);
- }else rlen=0;
- rlen=packet_encode(buf,len,U_LOGOUT,pb,rlen);
- if(NULL != pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryLogout(T_INT32 tcpSocket){
- T_UINT8 buff[10];//实际只需要5个字节即可
- T_UINT16 plen;
- memset(buff,0,sizeof(buff));
- plen=pa_logout(buff,sizeof(buff));
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //query group
- static T_UINT16 pa_query_group(T_BYTE* buffer,T_UINT32 plen, T_UINT32 queryGroupNum){
- T_UINT16 rlen;
- T_UINT8 *pb=NULL;
- QueryGroup msg;
- query_group__init(&msg);
- msg.has_max_groups=1;
- msg.max_groups=queryGroupNum;
- rlen=query_group__get_packed_size(&msg);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL){
- wlog_error("query group malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
- rlen = query_group__pack(&msg, pb);
- }else rlen=0;
- rlen = packet_encode(buffer, plen, U_QUERY_GROUP, pb, rlen);
- if(NULL != pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryQueryGroup(T_INT32 tcpSocket, T_UINT32 queryGroupNum){
- T_UINT8 buff[20];//实际需要10个字节
- T_UINT16 plen;
- memset(buff, 0, sizeof(buff));
- plen=pa_query_group(buff, sizeof(buff),queryGroupNum);
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //join group
- static T_UINT16 pa_active_group(T_BYTE* buffer,T_UINT32 len,T_GID gid)
- {
- T_UINT16 rlen;
- JoinGroup msg;
- T_UINT8 *pb=NULL;
- join_group__init(&msg);
- msg.gid = gid;
- rlen=join_group__get_packed_size(&msg);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL){
- wlog_error("join malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
- rlen = join_group__pack(&msg, pb);
- }else rlen=0;;
- rlen = packet_encode(buffer, len, U_ENTER_GROUP, pb, rlen);
- if(NULL != pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryJoinGroup(T_INT32 tcpSocket){
- T_UINT8 buff[14];//实际需要7个字节
- T_UINT16 plen;
-
- memset(buff, 0, sizeof(buff));
- plen=pa_active_group(buff, sizeof(buff),get_gid());
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //request mic
- static int pa_request_mic(T_BYTE* buffer,T_UINT32 len,T_GID gid,T_UID uid){
- T_UINT16 rlen;
- RequestMic msg;
- T_UINT8 *pb=NULL;
- request_mic__init(&msg);
- msg.has_gid=1;
- msg.gid = gid;
- msg.has_uid=1;
- msg.uid=uid;
- rlen=request_mic__get_packed_size(&msg);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL){
- wlog_error("requestmic malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
- rlen = request_mic__pack(&msg, pb);
- }else rlen=0;
- rlen = packet_encode(buffer, len, U_REQUEST_MIC, pb, rlen);
- if(NULL!=pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryReqMic(T_INT32 tcpSocket){
- T_UINT8 buff[18];//实际需要9个字节
- T_UINT16 plen;
- memset(buff, 0, sizeof(buff));
- plen=pa_request_mic(buff,sizeof(buff),get_gid(),get_uid());
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //release mic
- static int pa_release_mic(T_BYTE* buffer,T_UINT32 len,T_GID gid,T_UID uid){
- T_UINT16 rlen;
- ReleaseMic msg;
- T_UINT8 *pb=NULL;
- release_mic__init(&msg);
- msg.has_gid=1;
- msg.gid = gid;
- msg.has_uid=1;
- msg.uid=uid;
- rlen=release_mic__get_packed_size(&msg);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL){
- wlog_error("releasemic malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
- rlen = release_mic__pack(&msg, pb);
- }else rlen=0;;
- rlen = packet_encode(buffer, len, U_RELEASE_MIC, pb, rlen);
- if(NULL != pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryReleaseMic(T_INT32 tcpSocket){
- T_UINT8 buff[18];//实际需要9个字节
- T_UINT16 plen;
- //thisTalk->pttReqStatus=FALSE;
- memset(buff, 0, sizeof(buff));
- plen=pa_release_mic(buff,sizeof(buff),get_gid(),get_uid());
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //tempCall
- static int pa_call(T_BYTE* buffer,T_UINT32 len,T_UINT32 uid){
- T_UINT16 rlen;
- Call msg;
- T_UINT8 *pb=NULL;
- call__init(&msg);
- msg.n_uid=1;
- msg.uid=&uid;
- rlen=call__get_packed_size(&msg);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL)
- {
- wlog_error("pa_call malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
-
- rlen = call__pack(&msg, pb);
- }else rlen=0;
- rlen = packet_encode(buffer, len, U_MAKE_TMP_CALL, pb, rlen);
- if(NULL != pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryTempCall(T_INT32 tcpSocket,T_UID tuid){
- T_UINT8 buff[14];//实际需要7个字节
- T_UINT16 plen;
- memset(buff, 0, sizeof(buff));
- plen=pa_call(buff,sizeof(buff),tuid);
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //query members
- static T_UINT16 pa_query_member(T_BYTE* buffer,T_UINT32 len,T_GID *gid,T_UINT32 queryNum){
- T_UINT16 rlen;
- T_UINT8 *pb=NULL;
- QueryMembers msg;
- query_members__init(&msg);
- msg.n_gids=1;
- msg.gids=(uint32_t *)gid;
- msg.has_detail=1;
- msg.detail=QUERY_MEMBERS__DETAIL_LEVEL__USER_INFO;
- msg.has_max_members=1;
- msg.max_members=queryNum;
- rlen=query_members__get_packed_size(&msg);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL){
- wlog_error("query members malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
-
- rlen = query_members__pack(&msg, pb);
- }else rlen=0;
- rlen = packet_encode(buffer, len, U_QUERY_MEMBERS, pb, rlen);
- if(NULL != pb) wfree(pb);
- return rlen;
- }
- T_BOOL pocTryQuerymember(T_INT32 tcpSocket,T_GID *gid,T_UINT32 queryNum){
- T_UINT8 buff[22];//实际需要11个字节
- T_UINT16 plen;
-
- memset(buff, 0, sizeof(buff));
- plen=pa_query_member(buff, sizeof(buff),gid,queryNum);
- return poc_tx_data(tcpSocket,buff,plen);
- }
- //tcp heartTick
- T_UINT16 pa_ping(T_BYTE* buffer,T_UINT32 len)
- {
- T_UINT8 *pb=NULL;
- T_UINT16 rlen;
- Ping _ping;
- ping__init(&_ping);
- _ping.has_timestamp = 0;
- rlen=ping__get_packed_size(&_ping);
- if(rlen>0){
- pb=(T_UINT8 *)wmalloc(rlen);
- if(pb == NULL){
- wlog_error("ping malloc err");
- return 0;
- }
- memset(pb, 0, rlen);
- rlen = ping__pack(&_ping, pb);
- }else rlen=0;;
- rlen=packet_encode(buffer, len, PUSH_PING_ACK, pb, rlen);
- if(NULL != pb) wfree(pb);
-
- return rlen;
- }
- T_BOOL pocTryTcpHeart(T_INT32 tcpSocket){
- T_UINT8 buff_f[10];//实际需要5个字节
- T_UINT16 plen;
- memset(buff_f, 0, sizeof(buff_f));
- plen = pa_ping(buff_f,sizeof(buff_f));
- return poc_tx_data(tcpSocket, buff_f, plen);
- }
|