~vibhavp/ubuntu/raring/dahdi-tools/merge-from-debian

« back to all changes in this revision

Viewing changes to xpp/pic_loader.c

  • Committer: Vibhav Pant
  • Date: 2012-12-26 17:23:16 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: vibhavp@gmail.com-20121226172316-o2jojsfcnr0aqrme
* Merge from Debian unstable. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - debian/control: Added gawk as dependency for dkms build (LP: #493304)
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source 

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <regex.h>
28
28
#include "hexfile.h"
29
29
#include "pic_loader.h"
30
 
#include "debug.h"
 
30
#include <debug.h>
 
31
#include <xusb.h>
31
32
 
32
33
#define DBG_MASK        0x03
33
34
#define MAX_HEX_LINES   10000
87
88
        }
88
89
 
89
90
        DBG("PICLINE: pack_len=%d pcmd=%d\n", pack_len, pcmd);
90
 
        dump_packet(LOG_DEBUG, "dump:picline[W]", (char *)phead, pack_len);
 
91
        dump_packet(LOG_DEBUG, DBG_MASK, "dump:picline[W]", (char *)phead, pack_len);
91
92
 
92
 
        ret = send_usb(astribank, buf, pack_len, TIMEOUT);
 
93
        ret = xusb_send(astribank->xusb, buf, pack_len, TIMEOUT);
93
94
        if(ret < 0) {
94
 
                ERR("send_usb failed: %d\n", ret);
 
95
                ERR("xusb_send failed: %d\n", ret);
95
96
                return ret;
96
97
        }
97
 
        DBG("send_usb: Written %d bytes\n", ret);
 
98
        DBG("xusb_send: Written %d bytes\n", ret);
98
99
        if (recv_answer) {
99
 
                ret = recv_usb(astribank, buf, sizeof(buf), TIMEOUT);
 
100
                ret = xusb_recv(astribank->xusb, buf, sizeof(buf), TIMEOUT);
100
101
                if(ret <= 0) {
101
102
                        ERR("No USB packs to read\n");
102
103
                        return ret;
104
105
                        phead = (struct xpp_packet_header *)buf;
105
106
                        if(phead->header.op != PIC_REP_XOP) {
106
107
                                ERR("Got unexpected reply OP=0x%02X\n", phead->header.op);
107
 
                                dump_packet(LOG_ERR, "hexline[ERR]", buf, ret);
 
108
                                dump_packet(LOG_ERR, DBG_MASK, "hexline[ERR]", buf, ret);
108
109
                                return -EINVAL;
109
110
                        }
110
111
                        DBG("received OP=0x%02X, checksum=%02X\n", phead->header.op, phead->d.pic_packet.data[0]);
180
181
        uint8_t                 card_type;
181
182
        int                     ret;
182
183
        unsigned int            i;
 
184
        const char              *devstr;
183
185
 
184
186
        v = (v[0]) ? v : "Unknown";
185
187
        assert(astribank != NULL);
186
188
        assert(hexdata != NULL);
 
189
        devstr = xusb_devpath(astribank->xusb);
187
190
        if(!astribank->is_usb2) {
188
 
                ERR("Skip PIC burning (not USB2)\n");
 
191
                ERR("%s: Skip PIC burning (not USB2)\n", devstr);
189
192
                return 0;
190
193
        }
191
 
        INFO("Load PIC: %s (version %s)\n", hexdata->fname, hexdata->version_info);
 
194
        INFO("%s [%s]: Loading PIC Firmware: %s (version %s)\n",
 
195
                devstr,
 
196
                xusb_serial(astribank->xusb),
 
197
                hexdata->fname,
 
198
                hexdata->version_info);
192
199
        basename = pic_basename(hexdata->fname, &card_type);
193
200
        if(!basename) {
194
 
                ERR("Bad PIC filename '%s'. Abort.\n", hexdata->fname);
 
201
                ERR("%s: Bad PIC filename '%s'. Abort.\n", devstr, hexdata->fname);
195
202
                return 0;
196
203
        }
197
204
        DBG("basename=%s card_type=%d maxlines=%d\n",
200
207
         * Try to read extra left-overs from USB controller
201
208
         */
202
209
        for(i = 2; i; i--) {
203
 
                char    buf[PACKET_SIZE];
 
210
                char    buf[PACKET_SIZE];
204
211
 
205
 
                if(usb_bulk_read(astribank->handle, astribank->my_ep_in, buf, sizeof(buf), 1) <= 0)
 
212
                if(xusb_recv(astribank->xusb, buf, sizeof(buf), 1) <= 0)
206
213
                        break;
207
214
        }
208
215
        if((ret = send_picline(astribank, card_type, PIC_START_FLAG, 0, NULL, 0)) != 0) {
215
222
 
216
223
                hexline = hexdata->lines[i];
217
224
                if(!hexline) {
218
 
                        ERR("hexdata finished early (line %d)", i);
 
225
                        ERR("%s: hexdata finished early (line %d)", devstr, i);
219
226
                        return 0;
220
227
                }
221
228
                if(hexline->d.content.header.tt == TT_DATA) {
222
229
                        len = hexline->d.content.header.ll;     /* don't send checksum */
223
230
                        if(len != 3) {
224
 
                                ERR("Bad line len %d\n", len);
 
231
                                ERR("%s: Bad line len %d\n", devstr, len);
225
232
                                return 0;
226
233
                        }
227
234
                        data = hexline->d.content.tt_data.data;
235
242
                } else if(hexline->d.content.header.tt == TT_EOF) {
236
243
                        break;
237
244
                } else {
238
 
                        ERR("Unexpected TT = %d in line %d\n",
239
 
                                        hexline->d.content.header.tt, i);
 
245
                        ERR("%s: Unexpected TT = %d in line %d\n",
 
246
                                        devstr, hexline->d.content.header.tt, i);
240
247
                        return 0;
241
248
                }
242
249
        }
250
257
 
251
258
int load_pic(struct astribank_device *astribank, int numfiles, char *filelist[])
252
259
{
253
 
        int     i;
 
260
        int             i;
 
261
        const char      *devstr;
254
262
 
255
 
        DBG("Loading %d PIC files...\n", numfiles);
 
263
        devstr = xusb_devpath(astribank->xusb);
 
264
        DBG("%s: Loading %d PIC files...\n", devstr, numfiles);
256
265
        for(i = 0; i < numfiles; i++) {
257
266
                struct hexdata  *picdata;
258
267
                const char      *curr = filelist[i];
263
272
                        return -errno;
264
273
                }
265
274
                if(!pic_burn(astribank, picdata)) {
266
 
                        ERR("PIC %s burning failed\n", curr);
 
275
                        ERR("%s: PIC %s burning failed\n", devstr, curr);
267
276
                        return -ENODEV;
268
277
                }
269
278
                free_hexdata(picdata);
270
279
        }
271
280
        if((i = send_picline(astribank, 0, PIC_ENDS_FLAG, 0, NULL, 0)) != 0) {
272
 
                ERR("PIC end burning failed\n");
 
281
                ERR("%s: PIC end burning failed\n", devstr);
273
282
                return -ENODEV;
274
283
        }
275
284
        return 0;