source: svn/newcon3bcm2_21bu/nexus/lib/ipc/bipc_client.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 6.0 KB
Line 
1/******************************************************************************
2 *    (c)2011 Broadcom Corporation
3 *
4 * This program is the proprietary software of Broadcom Corporation and/or its licensors,
5 * and may only be used, duplicated, modified or distributed pursuant to the terms and
6 * conditions of a separate, written license agreement executed between you and Broadcom
7 * (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8 * no license (express or implied), right to use, or waiver of any kind with respect to the
9 * Software, and Broadcom expressly reserves all rights in and to the Software and all
10 * intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11 * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12 * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13 *
14 * Except as expressly set forth in the Authorized License,
15 *
16 * 1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17 * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18 * and to use this information only in connection with your use of Broadcom integrated circuit products.
19 *
20 * 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21 * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23 * THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25 * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26 * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27 * USE OR PERFORMANCE OF THE SOFTWARE.
28 *
29 * 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30 * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31 * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32 * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34 * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35 * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36 * ANY LIMITED REMEDY.
37 *
38 * $brcm_Workfile: bipc_client.c $
39 * $brcm_Revision: 1 $
40 * $brcm_Date: 10/4/11 5:44p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /nexus/lib/ipc/bipc_client.c $
47 *
48 * 1   10/4/11 5:44p vsilyaev
49 * SW7425-1364: Reference applicaion IPC and reference server
50 *
51 *****************************************************************************/
52#include "bstd.h"
53#include "bipc_impl.h"
54
55BDBG_MODULE(bipc_client);
56
57BDBG_OBJECT_ID(bipc_client);
58
59bipc_t bipc_client_create(int recv_fd, int send_fd, const bipc_interface_descriptor * const interfaces[], size_t interface_count)
60{
61    bipc_t ipc;
62    unsigned i;
63    size_t size;
64    BERR_Code rc;
65
66    BDBG_ASSERT(interfaces);
67    BDBG_ASSERT(interface_count>0);
68    for(size=0,i=0;i<interface_count;i++) {
69        BDBG_ASSERT(interfaces[i]);
70        size += interfaces[i]->buf_size;
71    }
72
73    ipc = BKNI_Malloc(size + sizeof(b_ipc_pkt_in) + sizeof(b_ipc_pkt_out)+sizeof(*ipc));
74    if(!ipc) {(void)BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto err_alloc;}
75
76    BDBG_OBJECT_INIT(&ipc->t.client, bipc_client);
77    ipc->t.client.ipc_buf_size = size;
78    ipc->t.client.recv_fd = recv_fd;
79    ipc->t.client.send_fd = send_fd;
80    ipc->t.client.interfaces = interfaces;
81    ipc->t.client.interface_count = interface_count;
82    rc = BKNI_CreateMutex(&ipc->t.client.lock);
83    if(rc!=BERR_SUCCESS) {rc=BERR_TRACE(rc);goto err_mutex;}
84
85    return ipc;
86err_mutex:
87    BKNI_Free(ipc);
88err_alloc:
89    return NULL;
90}
91
92
93void bipc_client_destroy(bipc_t ipc)
94{
95    BDBG_OBJECT_ASSERT(&ipc->t.client, bipc_client);
96    BKNI_AcquireMutex(ipc->t.client.lock);
97    BKNI_ReleaseMutex(ipc->t.client.lock);
98    BKNI_DestroyMutex(ipc->t.client.lock);
99    BDBG_OBJECT_DESTROY(&ipc->t.client, bipc_client);
100    BKNI_Free(ipc);
101    return;
102}
103
104void *bipc_client_begin(bipc_t ipc, const bipc_interface_descriptor *id)
105{
106    unsigned i;
107    BDBG_OBJECT_ASSERT(&ipc->t.client, bipc_client);
108    BKNI_AcquireMutex(ipc->t.client.lock);
109    if(id) {
110        bool found=false;
111        for(i=0;i<ipc->t.client.interface_count;i++) {
112            if(ipc->t.client.interfaces[i] == id) {
113                found = true;
114                break;
115            }
116        }
117        if(!found) {
118            return NULL;
119        }
120    }
121    return ipc->t.client.buf + sizeof(b_ipc_pkt_in);
122}
123
124
125
126int bipc_client_send(bipc_t ipc, unsigned id, unsigned entry, size_t send_size, size_t  recv_offset, size_t recv_size)
127{
128    struct b_ipc_pkt_in *in;
129    b_ipc_pkt_out out;
130    int rc;
131
132    BDBG_OBJECT_ASSERT(&ipc->t.client, bipc_client);
133    in = (void *)ipc->t.client.buf;
134    if(send_size + recv_size > ipc->t.client.ipc_buf_size) {
135        rc = -1;
136        (void)BERR_TRACE(BERR_NOT_SUPPORTED); goto done;
137    }
138    in->pkt_size = send_size + sizeof(*in);
139    in->method = entry;
140    in->instance = id;
141    rc = b_safe_write(ipc->t.client.send_fd, in, in->pkt_size);
142    if(rc!=(int)in->pkt_size) { (void)BERR_TRACE(BERR_NOT_SUPPORTED);goto done; }
143    rc = b_safe_read(ipc->t.client.recv_fd, &out, sizeof(out));
144    if(rc!=sizeof(out)) { (void)BERR_TRACE(BERR_NOT_SUPPORTED);goto done; }
145    if(out.pkt_size != recv_size + sizeof(out)) {
146        rc = -1;
147        (void)BERR_TRACE(BERR_NOT_SUPPORTED);goto done; 
148    }
149    if(recv_size) {
150        rc = b_safe_read(ipc->t.client.recv_fd, ipc->t.client.buf + sizeof(b_ipc_pkt_in) + recv_offset, recv_size);
151        if(rc!=(int)recv_size) { (void)BERR_TRACE(BERR_NOT_SUPPORTED);goto done; }
152    }
153    rc = 0;
154done:
155    return rc;
156}
157
158void bipc_client_end(bipc_t ipc)
159{
160    BDBG_OBJECT_ASSERT(&ipc->t.client, bipc_client);
161
162    BKNI_ReleaseMutex(ipc->t.client.lock);
163    return;
164}
165
Note: See TracBrowser for help on using the repository browser.