Click here to Skip to main content
Click here to Skip to main content

How to retrieve DVD region information

, 1 Aug 2006
Rate this:
Please Sign up or sign in to vote.
An article showing you how to programmatically retrieve DVD region information

Sample Image - mydvdregion.jpg

Introduction

I've been playing with DVDs recently and stumbled upon many tools for DVD backup, DVD region-free tools, and such. In this article we are going to demonstrate how to programmatically retrieve the DVD's region information.

What is DVD Region?

In short it is a mechanism encoded both in DVD players and on DVD discs dictating if a DVD player can play a certain DVD disk. The DVD region in the DVD player is stored inside the hardware and cannot be reset if windows is re-installed or the player was moved to another PC. Some ways to circumvent this is to update your player's firmware and remove the DVD region support from it. The DVD region in the DVD movie is stored inside one of its IFO file.

From [1] we have the following regions:

Region Code Region Name
0 No Region Coding
1 United States of America, Canada
2 Europe, including France, Greece, Turkey, Egypt, Arabia, Japan and South Africa
3 Korea, Thailand, Vietnam, Borneo and Indonesia
4 Australia and New Zealand, Mexico, the Caribbean, and South America
5 India, Africa, Russia and former USSR countries
6 Peoples Republic of China
7 Unused
8 Airlines/Cruise Ships
9 Expansion (often used as region free)

DVD region has been defined extensively on the net please check this article's references.

Technical prerequisites

In order to read information from the DVD drive we are going to issue SCSI commands to the hardware itself (DVD player). For simplicity, this article's code do not use ASPI instead uses Microsoft's SPTI (SCSI Pass Through Interface) to talk with the hardware. The SCSI commands issued to the hardware are standards and can be found on the net [3].

Using SPTI to issue SCSI commands

Sending SCSI / CDBs (command descriptor blocks) to the device is very simple with the SPTI interface and consists of only setting up the correct block and sending it.

  1. Open the device, say: \\.\C:\
  2. Prepare a SCSI_PASS_THROUGH_DIRECT structure
  3. Prepare the CDB (Command Descriptor Block), a structure used to select which command and pass appropriate parameters ([4] [6])
  4. Prepare the return or data buffer (buffer returned after the command is issued)
  5. Use DeviceIoControl() with IOCTL code value of IOCTL_SCSI_PASS_THROUGH_DIRECT (value 0x4D014) to issue the call
  6. Interpret the results

Reading the DVD region

After reading in [5] we realize that we need to send to the DVD the SCSI operation code SCSIOP_REPORT_KEY (value 0xA4) with some specific parameters.

The REPORT_KEY can be used to do many things, but we only need to read the DVD region information, for that we fill the "CDB_REPORT_KEY" as:

OperationCode = SCSIOP_REPORT_KEY
AllocationLength = sizeof(REPORT_KEY_DATA_RPC_STATE)
AGID = 0
KeyFormat = KEY_FORMAT_RPC_STATE

After the command is issued, a REPORT_KEY_DATA_RPC_STATE ([5] page 533) will be filled with the region information.

Quoted and paraphrased from [5]:

# of Vendor Resets Available = is a count down counter that indicates the number of times that the vendor may reset the region. The manufacturer of the Drive sets this value to 4 and the value is decremented each time the vendor clears the Drive’s region. When this value is zero, the vendor may no longer clear the Drive's region.

# of User Controlled Changes Available = is a count down counter that indicates the number of times that the user may set the region. This value is initially 5.

The Region Mask returns a value that specifies the Drive Region in which the Drive is located. Once the Drive Region has been set, the Drive shall be located in only one region. Each bit represents one of eight regions. If a bit is cleared in this field, the disc may be played in the corresponding region. If a bit is set in this field, the disc may not be played in the corresponding region. Only one bit can be cleared.

Example: if region mask is 0xFE which is 11111110 in binary means that bit1 is cleared thus region 1 is set.

RPC Scheme specifies the type of Region Playback Controls being used by the Drive.
We currently have two schemes RPC1 which do not enforce region playback control, and RPC2 which enforces the region playback control.

The code

void print_region_info(HANDLE device)
{
  static char *region_names[] = 
  {
   "United States of America, Canada", // Region 1
   "Europe, including France, Greece, Turkey, Egypt, Arabia, "
"Japan and South Africa", // 2
   "Korea, Thailand, Vietnam, Borneo and Indonesia", // 3
   "Australia and New Zealand, Mexico, the Caribbean, and South America", // 4
   "India, Africa, Russia and former USSR countries", // 5
   "Peoples Republic of China", // 6
   "Unused", // 7
   "Airlines/Cruise Ships" // 8
  };

  static char *region_set[] =
  {
    "No region set", // 0
    "Region set", // 1
 
    // 2
    "Drive region is set. Additional restrictions required to make changes",
    "Region set permanently, but may be reset by vendor", // 3

  };

  REPORT_KEY_DATA_RPC_STATE region = {0};
  CDB_REPORT_KEY report = {0};

  report.OperationCode = SCSIOP_REPORT_KEY;
  report.AllocationLength = sizeof(REPORT_KEY_DATA_RPC_STATE);
  report.AGID = 0;
  report.KeyFormat = KEY_FORMAT_RPC_STATE;

  if (!carry_cdb(device, &report, sizeof(report), ®ion, sizeof(region)))
  {
    printf("Could not get region info!\n");
    return;
  }

  unsigned char region_code = ~region.region_mask;
  int i;

  char *region_name = "No Region Coding";
  for (i=7;i>=0;i--)
  {
    if ( (1 << i) & region_code) 
    {
      region_name = region_names[i];
      break;
    }
  }

  printf(
    "Region Information:\n"
    "-------------------\n"
    "Vendor changes: %d\n"
    "User changes: %d\n"
    "Region name: %s\n"
    "Type code: %s\n",
    region.nb_vendor_resets,
    region.nb_user_changes,
    region_name,
    region_set[region.type_code]
    );
}

How to programmatically set DVD region?

I did not try it, but apparently one has to issue a SEND_KEY command with appropriate structures. Check [5] page 587.

Conclusions

Hope you learned a little from this article and got pointers about where to look further.
If I find interest and time, perhaps I will extend my knowledge beyond this and write more articles. Meanwhile, happy coding.

References

  • [1] http://www.hometheaterinfo.com/dvd3.htm
  • [2] http://www.codefreedvd.com/dvd_dvdregionlockingexplained.htm
  • [3] http://www.t10.org/
  • [4] http://en.wikipedia.org/wiki/SCSI_CDB
  • [5] T10.org [3] / SCSI Multi-Media Commands – 5 (MMC-5) / mmc5r03a.pdf
  • [6] DDK / SCSI_PASS_THROUGH documentation

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Elias Bachaalany
Web Developer
United States United States
Elias (aka lallousx86, @0xeb) has always been interested in the making of things and their inner workings.
 
His computer interests include system programming, reverse engineering, writing libraries, tutorials and articles.
 
In his free time, and apart from researching, his favorite reading topics include: dreams, metaphysics, philosophy, psychology and any other human/mystical science.
 
Former employee of Hex-Rays (the creators of IDA Pro), was responsible about many debugger plugins, IDAPython project ownership and what not.
 
Elias currently works at Microsoft as a software security engineer.
 
More articles and blog posts can be found here:
 
- http://lallousx86.wordpress.com/
- http://0xeb.wordpress.com/
- http://www.hexblog.com/?author=3

Comments and Discussions

 
QuestionMedia Code PinmemberPascal Damman22-Jul-11 0:46 
AnswerRe: Media Code PinmemberElias Bachaalany22-Jul-11 1:29 
GeneralEgypt PinmemberJiggawha26-May-10 14:07 
QuestionDVD TYPE Pinmemberjxy3331619-Sep-08 6:38 
QuestionPlease tell me how to set the DVD region by C++ coding Pinmemberjxy3331619-Sep-08 6:36 
GeneralDVD region Set Pinmemberargo77717-Dec-07 6:53 
GeneralSPTI (SCSI Pass Through Interface) and changer Pinmemberfredguo29-Jan-07 9:28 
GeneralRe: SPTI (SCSI Pass Through Interface) and changer Pinmemberlallous31-Jan-07 5:32 
GeneralCD/DVD Configuration Pinmemberrbrunton25-Aug-06 11:05 
This project is helpful, but I'm still struggling with trying to get the basic information about the device. What I want to know is whether the drive is a CD-RW, CD-ROM, DVD-R, DVD+R or DVD-RW. The Command Data Block request code is 0x46. My problem (I think) is that I have not constructed the structure to accept the returned data properly and the function (that was created in the DVD region project - carry_cdb) hangs.
 
Any ideas where I can get clear information on how to construct this structure? The Linux/Unix library "libcdio" does it all I think, but I'm lost trying to navigate the code to implement it for Windows. Any suggestions or help would be greatly appreciated.
 
TIA
 
Ron
GeneralRe: CD/DVD Configuration Pinmemberlallous1-Sep-06 0:12 
Jokehttp://college-football-helmets.tangoing.info/ Pinsusshttp://college-football-helmets.tangoing.info/4-Dec-07 2:15 
GeneralManaged wrapper request Pinmemberlallous3-Aug-06 11:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 1 Aug 2006
Article Copyright 2006 by Elias Bachaalany
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid