+#define PICTURE_WIDTH (72)
+#define PICTURE_HEIGHT (28)
+
+static inline void pictureread(void)
+{
+FILE *f;
+unsigned char bin1[140]={
+ 6, /* UDH length */
+ 0x05, /* IEI */
+ 0x04, /* IEDL */
+ 0x15, 0x8A, /* dest port (ring tones) */
+ 0x15, 0x8A /* src port (unused) */
+#define BIN1_PAYLOAD (140-7)
+ };
+unsigned char binn[140]={
+ 11, /* UDH length */
+ 0x05, /* IEI */
+ 0x04, /* IEDL */
+ 0x15, 0x8A, /* dest port (ring tones) */
+ 0x15, 0x8A, /* src port (unused) */
+ 0x00, 0x03, /* multipart */
+ /* 0x??, unique serial ID */
+ /* 0x??, total messages */
+ /* 0x??, message number (# from 1) */
+#define BINN_PAYLOAD (140-12)
+ };
+unsigned char header[]={
+ 0x30, /* version string '0' */
+ 0x02, /* item=OTA bitmap */
+#define PICTURE_BYTES ((PICTURE_WIDTH*PICTURE_HEIGHT+7)/8)
+#define PICTURE_BYTES_INCL_HEADER (PICTURE_BYTES +4/*header*/)
+ PICTURE_BYTES_INCL_HEADER>>8,PICTURE_BYTES_INCL_HEADER&0xFF, /* picture size in bytes incl. header */
+ 0x00, /* animation pictures - 0=static picture */
+ PICTURE_WIDTH,PICTURE_HEIGHT, /* picture size in pixels */
+ 0x01, /* picture depth - B/W */
+ };
+size_t got,want;
+int totn,fragn;
+long size;
+
+#define WORD(n) (((unsigned char)buf[(n)])|(((unsigned char)buf[(n)+1])<<8))
+
+ if (!(f=fopen(picturename,"rb")))
+ error(_("^!Cannot open picture file \"%s\" for r/o"),picturename);
+ if ((size=getfilesize(f,picturename))==-1)
+ error(_("!File size determination is essential to continue operation"));
+ if (size!=PICTURE_BYTES)
+ error(_("!File \"%s\" size %ld doesn't match .res size for %dx%d picture"),
+ picturename,size,PICTURE_WIDTH,PICTURE_HEIGHT);
+ if (size<=BIN1_PAYLOAD-sizeof(header)) {
+ memcpy(bin1+7,header,sizeof(header));
+ if ((got=fread(bin1+7+sizeof(header),1,size,f))!=size)
+ error(_("^Read error on \"%s\", wanted %ld, got %d"),picturename,size,got);
+ error(_("\nSending picture \"%s\" as single SMS (size %ld, max %d)"),
+ picturename,size,BIN1_PAYLOAD-sizeof(header));
+ nokiaprep(bin1,7+sizeof(header)+size);
+ }
+ else {
+ memcpy(binn+12,header,sizeof(header));
+ totn=(sizeof(header)+size+BINN_PAYLOAD-1)/BINN_PAYLOAD;
+ if (totn>0xFF)
+ error(_("!File size %ld too large even for multi-SMS picture upload (max=%d)"),
+ size,BINN_PAYLOAD*0xFF-sizeof(header));
+ binn[10]=totn;
+ if (verbose>=1)
+ error(_("\nSending picture \"%s\" as %d multi-SMSes (size %ld, max %d, frag %d, header %d)"),
+ picturename,totn,size,BIN1_PAYLOAD,BINN_PAYLOAD,sizeof(header));
+ binn[9]=time(NULL)&0x100; /* rand() would be better but it is a compatibility pain */
+ if (verbose>=1)
+ error(_("\nUsing unique multi-SMS ID 0x%02X"),(unsigned)binn[9]);
+ for (fragn=1;fragn<=totn;fragn++) {
+size_t isheader=(fragn==1 ? sizeof(header) : 0);
+
+ binn[11]=fragn;
+ want=MIN(size,BINN_PAYLOAD-isheader);
+ if ((got=fread(binn+12+isheader,1,want,f))!=want)
+ error(_("^Read error on \"%s\", wanted %d, got %d"),picturename,want,got);
+ nokiaprep(binn,12+isheader+want);
+ size-=want;
+ }
+ }
+ chkfclose(f,picturename);
+#undef WORD
+}
+